X-Y Grid-based Wire Numbering - Based on wire number pick points - AutoCAD Electrical

  • Coinciding with the acquisition of VIA Development, Nate joined Autodesk in March of 2003 after a decade stint as an entrepreneur following a two-decade stint as a controls engineer and software applications developer at Owens-Corning. Nate is now the lead product architect for AutoCAD Electrical. He loves this stuff.

    About Nate

Latest Post

  • X-Y Grid-based Wire Numbering - Based on wire number pick points - AutoCAD Electrical
    October 1, 2008, 08:51 AM Nate Holt

    AutoCAD Electrical normally makes wire number assignments based on the “beginning” XY point of a wire network.  Here’s a nifty utility to let you override this behavior. You can have wire number assignments be based on the XY point of a manual pick on each wire network.

    This originated from a user request. Here’s the default AutoCAD Electrical behavior for wire numbering in an X-Y grid-based tagging mode.

    Three wire networks are tagged “1-A”, “1-B”, and “1-C” because each wire network “begins” in those X-Y zones.

    But the user really wants to reposition the wire numbers as shown below. No problem. Just use the MOVE WNUM command and pick as shown.

    But here is the kicker. The user really wants the wire number assignment to match up with the X-Y position of where the wire number has been positioned on the wire network. So, in the screenshot above, he wants wire number “1-B” to really be “2-A” since the wire number text is now in the 2-A X-Y grid location. And he wants “1-C” to really be “2-B”.

    Well, can do this by using the EDIT WIRE NUMBER command on each of these two re-positioned wire numbers and manually forcing them to be the new values.
    Painful.
     
    AutoCAD Electrical’s API to the rescue.

    How about creating a little AutoLISP utility to make this easier. You would launch the utility. It would prompt you to pick locations on each wire network. For each pick, it would read the X-Y grid location, figure out the appropriate wire number, and pop it in as a “fixed” wire number with that value. So, in operation, it would look like this:

    Here’s the utility! Download here: files/22201_22300/22240/file_22240.lsp 

    Rename the file wire2pick.lsp. Then APPLOAD it. Type WIRE2PICK [Enter] at the “Command:” prompt to launch the utility.

     How does this thing work?

    It makes use of a number of API calls built into AutoCAD Electrical. To get to the API documentation, select "Electrical Help Topics" from the HELP pull-down menu. Then pick on the "API Help" item along the right-hand list you should see in the help dialog.

    Here is the main part of the utility with some running commentary in italics.

      ; Get list of existing wire nums on the active drawing
      (if (not dwg_wirenum_lst)
        (setq dwg_wirenum_lst (wd_wnum_get_dwg_wnum_list))
      ) 
      (setq xitflg nil)
      (while (not xitflg)
        (setq xitflg T) ; default to exit loop
    ; this next line prompts user to pick where the wire number is to be inserted        
        (setq x (entsel "\nNext wire number insertion point (pick on wire):"))
           
        (if x
          (progn ; something picked, keep going!
            (setq xy (cadr x)) ; pick point
            (setq wen (car x)) ; entity name of wire
            (setq reftxt (car (wd_1_get_xr xy)))
            (setq str reftxt)
            (setq new_w reftxt)
            (setq same_lr_cnt 0)
            ; Calculate the wire number
            (setq new_w (wd_1a_fmt_into_fmt (list fmt reftxt ""
                             pc_h pc_v pc_s pc_d pp p_i pl
                             (wd_wnum_get_next_suffix same_lr_cnt suffix_lst)
                             curdwg_sec curdwg_subsec
                             w_layer
                             ) 1 ))
            ; Make sure wire number not used before. If so, increment suffix until unique.            
            (while (member new_w dwg_wirenum_lst)
              (setq new_w (wd_1a_fmt_into_fmt (list fmt reftxt ""
                        pc_h pc_v pc_s pc_d pp p_i pl
                        (wd_wnum_get_next_suffix same_lr_cnt suffix_lst)
                        curdwg_sec curdwg_subsec
                        w_layer
                        ) 1 ))
              (setq same_lr_cnt (1+ same_lr_cnt))
            )     

            (setq ed (entget wen)) ; open up the entity, see if it is a LINE entity
            (if (= (cdr (assoc 0 ed)) "LINE")
              (progn ; looks good so far      
                ; Make sure that this line is on a valid wire layer - AcadE API call
                (if (not (wd_lay_verify_wire_lay (cdr (assoc 8 ed))))
                  (progn ; Not on a wire layer. Display error msg.
                    (princ "Line is not on a wire layer")
                    (setq xitflg nil) ; stay in loop but do not increment wire number
                  )
                ; ELSE
                  (progn
                    ; Some error checking here - Make sure that this network does not
                    ; carry a "Destination" arrow. This means that
                    ; we cannot predefine the wire number on this
                    ; network (it must be defined on the "source"
                    ; part of the network)
                    (setq netlst (c:wd_get_wire_netlst wen 1)) ; AcadE API call
                    (if Z_prev (command "_.ZOOM" "_PREV"))
                    (setq Z_prev nil)
                    (if (nth 5 netlst)
                      (progn
                        (princ (strcat "\n Destination arrow on this"
                          " network. Fixed wire number not allowed."))
                        (setq xitflg nil) ; stay in loop but do not
                                          ; increment wire number
                      )
                   ; ELSE
                      (progn 
                        (setq skip nil)
                        (setq existing (c:ace_get_wnum wen)) ; this is an AcadE API call
                        (if (/= overwrite "A")
                          (progn ; Check if this wire network already
                                 ; has a wire number assignment
                            (if existing
                              (progn ; returns x=(list wnum wnum_blk_en)                               
                                (princ " existing= ")
                                (princ (car existing))
                                (setq x (getstring " Overwrite? (Y/<N>/yes to All)":))
                                (if (= (strcase (substr x 1 1)) "A")
                                  (progn ; overwrite all, do not prompt
                                    (setq overwrite "A")
                                    (setq xitflg nil) ; stay in loop
                                  )
                                ; ELSE
                                  (if (OR (= (strcase (substr x 1 1)) "N") (= x ""))
                                    (progn ; do not overwrite existing wnum
                                      (setq xitflg nil) ; stay in loop but don't increment
                                      (setq skip T)
                        ) ) ) ) ) ) )
       
                        (if (not skip)
                          (progn ; okay to insert the fixed wire number now!
                             
                                 ; Delete any old wire number at its position
                                 ; to make way for new wire number inserted
                                 ; at new pick point.
                            (if existing (c:ace_del_wnum wen)) ; another AcadE API call
                            (setq x (c:wd_putwnxyf xy new_w)) ; another AcadE API call
                            (if x
                              (progn
                                ; Save wire number in active dwg's list of existing
                                ; wire numbers
                                (setq dwg_wirenum_lst (cons new_w dwg_wirenum_lst))
                                (setq xitflg nil) ; stay in loop
                        ) ) ) )
                        (if Z_prev (command "_.ZOOM" "_PREV"))
                        (setq Z_prev nil)
     
                ) ) ) )
              )
            ; ELSE
              (progn ; not a LINE
                (princ " ??")
                (setq xitflg  nil) ; stay in loop but don't increment wire number text
            ) )   
      ) ) )     

    0 Comment | Add Comment Controlling the Machine >

Comments



You must be logged in to post a comment.

Subscribe to Blog

Want to keep up with the latest? Subscribe to the RSS feed today.

RSS

Tags

You must be logged in to add a tag.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback