Pushing Wiretype settings to signal arrows - AutoCAD Electrical

  • Controlling the Machine is no longer being updated. Don't worry, though, you can still follow Nate Holt at his new blog, AutoCAD Electrical Etcetera. You'll find it at http://nateholt.wordpress.com. Or you can subscribe to his feed to get latest words of wisdom automatically: http://nateholt.wordpress.com/feed/. You also can continue to view the Controlling Machine archives for Nate's AutoCAD Electrical tips and tricks.

    About Nate

Latest Post

  • Pushing Wiretype settings to signal arrows - AutoCAD Electrical
    October 9, 2008, 11:26 PM Nate Holt

    This posting is triggered by a recent user request. The Create Wiretype command allows a number of wire parameters to be associated to a given wire layer. But how can these be accessed with a user-created utility?

    The need is to look at each source/destination arrow symbol, find the attached wire, and determine the wire type (i.e. the wire "layer" name). Then access the defined data for the given wire type. Pull two of this wire type's parameters from its definition and push them on to two new attributes the user has added to his source/destination arrow symbols.

    This solution is in two parts: 1) modify the library symbols to include the new target attributes, and 2) create a little AutoLISP utility to find the wiretype data related to the wire tied to each source/destination arrow symbols and push two elements of this data back into the symbol as visible values on the two new target attributes.

    Add two new attributes to the Source/Destination arrow symbols

    This is the first step. User adds attributes COLOR and SIZE to each of the arrow symbols. In this example the attribute definitions are located just below the XREF attribute that carries the "From xxx" or "To xxx" cross-reference annotation.

    All done. That's the simple, boring part. Now the fun part begins... creating the software application to make it all work.

    How this think will work

    Let's design it so that the utility prompts the user to pick on each signal source or destination arrow symbol. The utility reads the symbol and confirms that it is a source or destination symbol. Then it finds the wire tied to the symbol and extracts the wire's layer name (i.e. the wire's "wire type").

    Next it makes an API call to query the scratch database to find all wiretypes tied to the active drawing. On the record that matches the passed layer name, it returns the list of color, size, and USERn values assigned to this wire type.

    It pulls out the color and size values and pushes them out to the two new attributes found on the source/destination arrow symbols.

    That's it!

    Here is the application:

    ; ** 09-Oct-2008 NEHolt created
    ; --------   W I R E T Y P E _ A N N O . L S P  -------
    (defun c:wiretype_anno ( / rtrn dwgix laynam ben blknam
                      color size x ed wtlst lst wen xitflg)
      ; PURPOSE: push WIRETYPE's "color" and "size" settings
      ;    out to target attributes on picked Source or
      ;    Destination arrow symbol.
     
      ; -- internal functions --

      (defun get_wiretype_data ( laynam / rtrn dwgix)
        ; Find and return all data tied to target "laynam"
        ; on active drawing in active project.
        ; "laynam" = wiretype layer name
        (setq rtrn nil)
        (setq dwgix nil)
        ; Set global GBL_wd_cip which carries the position
        ; that active drawing is in relative to all drawings
        ; listed in the project's ".wdp" file.
        (if (OR (= GBL_wd_cip 0)(not GBL_wd_cip))
          (wd_wdp_is_active_in_proj)) ; set the global
        ; Now figure out the drawing's DWGIX value that
        ; is used in the project's scratch database to
        ; identify this active drawing. 
        (if (/= GBL_wd_cip 0)
          (setq dwgix (wd_mdb_wdp2ix_ix GBL_wd_cip)))
        ; Now call an API function that queries the
        ; active project's scratch database file tables
        ; WIRETYPE and WIRETYPE_USR to find all
        ; info about wiretype "laynam" as defined on
        ; the active drawing (i.e. the active drawing's
        ; "DWGIX" value. 
        (if (AND laynam (/= laynam "") dwgix)
          (setq rtrn (ace_query_wiretype dwgix laynam))
        ) 
        rtrn ; nil=not found, otherwise a list of wire
             ; type COLOR, SIZE, and USER1-USER20
      )
     
      ; -- main program starts here --
      (setq xitflg nil)
      (while (not xitflg)
        (setq xitflg T) ; default to exit loop
        ; Prompt user to pick on Source/Destination
        ; arrow that needs to be annotated.
        (setq x (entsel "\nSelect source/destination arrow:"))
        (if x
          (progn
            (setq ben (car x)) ; entity name of pick
            (setq ed (entget ben)) ; open it
            (if (= (cdr (assoc 0 ed)) "INSERT")
              (progn ; so far, so good
                (setq blknam (cdr (assoc 2 ed)))
                ; Make sure it is an arrow symbol
                (if (wcmatch blknam "?A#S*,?A#D*")
                  (progn ; yes, keep going
                    ; Look for attached wire
                    (setq lst (c:wd_get_sym_pntlst ben 1 nil))
                    (if lst
                      (progn ; go for first or only connection
                        (setq wen (car (nth 3 (car lst))))
                        ; Get layer name of connected wire
                        (setq laynam (cdr (assoc 8 (entget wen))))
                        ; Now get COLOR and SIZE info for this
                        ; wire type
                        (setq wtlst (get_wiretype_data laynam))
                        (if wtlst
                          (progn ; have some data
                            (setq color (car wtlst))
                            (setq size (cadr wtlst))
                            ; Push these on to the Source/Dest
                            ; arrow symbol.
                           
                            ; ** SET TARGET ATTRIBUTE HERE **
                            (c:wd_modattrval ben "COLOR" color nil)
                            (c:wd_modattrval ben "SIZE" size nil)
                           
                            (setq xitflg nil) ; stay in loop
      ) ) ) ) ) ) ) ) ) ) )
      (princ) ; quiet return
    )

    You can download this file here: files/22201_22300/22257/file_22257.lsp

    ... then

    1. rename the downloaded file to "WIRETYPE_ANNO.LSP"

    2. to run, open target drawing and APPLOAD your renamed file "WIRETYPE_ANNO.LSP".

    3. Type WIRETYPE_ANNO [Enter] and the command line and start selecting the source/destination symbols to adjust.

     

     

     

    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