Thursday, August 8, 2013

Adding Cross Reference (XREF) Info To Footprints – AutoCAD Electrical

imageToday I was asked how to pull cross reference info from the parent symbol into a footprint. This works great on child components. Simply add an XREF attribute to a child component (if its missing) and on placement it auto populates with the parents sheet and reference location. However add an XREF to a footprint and nothing happens to it.
Out of the box, footprints do not pull this information even if the footprint contains an XREF attribute. However this information is available because multiple commands reference the footprints back to the parent symbol. None is more visible than the Surfer

image

In the surfer dialog above we can clearly see a reference between the parent, a child, and the footprint. So the question is, how do we go about getting this information info the footprint?
Below is a nifty utility wrote by Nate Holt back in 2009. (I tested it in 2014 and it still works great) It uses the same calls to the database that the Surfer users to capture this information and then writes it into an attribute named XREF on all the selected footprints.
Simple APPLOAD it and then type the command PANEL_CROSSREF

Add an XREF attribute                 Run the command                   Select the footprint                 Press enter…
image   image  image image

If you don’t like the formatting, it can be changed in the lsp. by modifying this line…
                    (setq cross_ref_str (strcat sheet "/" ref))I highlighted it in red in the code below as well.

Here's the utility:


; ** 24-Mar-09 NEHolt
; -------   P A N E L _ C R O S S R E F . L S P  --------
(defun c:panel_crossref ( / ss active_dwg_INST active_dwg_LOC x tag loc inst
            slen ix ben hit cross_ref_str rec ref str query_data sheet
            termno scratch_fnam panel_xref_attrib_name)
  ; PURPOSE: push schematic parent cross-reference info on to panel footprint
  ;          symbols if target cross-reference attribute is present.
 
  ; Set the target attribute name for this special cross-referencing
  (setq panel_xref_attrib_name "XREF")
 
  ; Get active project's "scratch database" file name
  (if (setq scratch_fnam (c:wd_mdb_get_proj_scratch_dbnam nil))
    (progn ; Now have active project's scratch database filename
      ; Read the active drawing's "WD_M" block values. This will carry
      ; the active drawing's default INST and LOC assignments which
      ; may be needed later.           
      (if (not GBL_wd_m) (wd_cfg_read_dwg_params))
      (setq active_dwg_INST (nth 52 GBL_wd_m))
      (setq active_dwg_LOC (nth 53 GBL_wd_m))     
           
      ; Now prompt user to select footprint and panel terminal symbols
      ; to process.
      (princ "\nSelect footprint and/or panel terminals to process:")
      (setq ss (ssget '((0 . "INSERT")))) ; gather up selected INSERTs
      (if (/= ss nil)
        (progn ; some INSERT instances selected, okay to proceed
           
          ; Begin to process the picked block INSERT instances on active
          ; drawing.
          (setq slen (sslength ss)) ; number of entities picked
          (setq ix 0) ; will be used to index through them
          (while (< ix slen)
            (setq ben (ssname ss ix)) ; get next entity to process
            (setq ix (1+ ix)) ; increment index for next time
            ; Determine what this block insert is
            (setq x (c:wd_is_it_pnl ben))
            (cond
              ((= x "FP") ; panel footprint
                (setq tag (c:wd_get_pnlval ben "P_TAG*"))
                (setq loc (c:wd_get_pnlval ben "LOC"))
                (setq inst (c:wd_get_pnlval ben "INST"))
               
               
                ; if LOC or INST blank, substitute in the drawing-wide
                ; default assignment.               
                (if (= loc "")(setq loc active_dwg_LOC))
                (if (= inst "")(setq inst active_dwg_INST))
               
                ; Call internal "surfer" query function               
                (setq query_data (wd_surfa_getcmprefs (list tag inst loc) nil nil))
                ; Sort through returned data. Look for schematic parent
                (setq hit nil)
                (foreach rec (car query_data)
                  (if (not hit)
                    (progn
                      ; Format of rec will be: (list type par1chld2 nonc ref sheet ? ? ...)
                      ; where type = "1" for schem parent
                      (if (AND (= (nth 0 rec) "1") ; schematic symbol
                               (= (nth 1 rec) "1")) ; and it's a parent
                        (progn
                          (setq hit rec)
                ) ) ) ) )
                (if hit
                  (progn ; Found match. Format the cross reference text
                    (setq sheet (nth 4 hit))
                    (setq ref (nth 3 hit))
                    (setq cross_ref_str (strcat sheet "/" ref))
                    ; Push cross-ref out to target attribute
                    (if (not (c:wd_modattrval ben panel_xref_attrib_name cross_ref_str nil))
                      (progn ; problem
                        (princ "\nNo ")
                        (princ panel_xref_attrib_name)
                        (princ " attribute found on panel footprint ")
                        (princ tag)
                        (princ " for cross-ref ")
                        (princ cross_ref_str)
                    ) )
              ) ) )
              ((= x "FPT") ; panel terminal
                (setq tag (c:wd_get_pnlval ben "P_TAGSTRIP*"))
                (setq termno (c:wd_getattrval ben "WIRENO,TERM01,TERM"))
                (setq loc (c:wd_get_pnlval ben "LOC"))
                (setq inst (c:wd_get_pnlval ben "INST"))             
                ; if LOC or INST blank, substitute in the drawing-wide
                ; default assignment.               
                (if (= loc "")(setq loc active_dwg_LOC))
                (if (= inst "")(setq inst active_dwg_INST))
                ; Call internal "surfer" query function               
                (setq query_data (wd_surfa_getcmprefs (list tag inst loc) nil "2"))
                ; Sort through returned data. Look for schematic parent with same terminal
                ; number value.
                (setq hit nil)
                (foreach rec (car query_data)
                  (if (not hit)
                    (progn
                      ; Format of rec will be: (list type ? ? ref sheet ? termno ...)
                      ; where type = "T" for schem terminal
                      (if (AND (= (nth 0 rec) "T") ; schematic terminal
                               (= (nth 6 rec) termno)) ; match on schem terminal number
                        (progn
                          (setq hit rec)
                ) ) ) ) )
                (if hit
                  (progn ; Found match. Format the cross reference text
                    (setq sheet (nth 4 hit))
                    (setq ref (nth 3 hit))
                    (setq cross_ref_str (strcat sheet "/" ref))
                    ; Push cross-ref out to target attribute
                    (if (not (c:wd_modattrval ben panel_xref_attrib_name cross_ref_str nil))
                      (progn ; problem
                        (princ "\nNo ")
                        (princ panel_xref_attrib_name)
                        (princ " attribute found on panel terminal ")
                        (princ termno)
                        (princ " for cross-ref ")
                        (princ cross_ref_str)
                    ) )
              ) ) )
          ) )
          (setq ss nil) ; release the selection set
      ) )   
  ) )
  (princ)
)  
Download a copy of the file here… https://skydrive.live.com/redir?resid=CE5A96771F5F2F9E!322&authkey=!ACdSIuPSgf0JwuY
To use:     1. You will need to add attribute’s named XREF to all panel footprints and terminal footprints that need this functionality.
     2. APPLOAD the lsp file. Type PANEL_CROSSREF [Enter]. Select all panel footprints to update and press enter.

1 comment:

  1. Wow! That is so cool! Is there a way to add this lisp to the Wire Annotation command. I can imagine that if a footprint has an XREF attribute, then it gets updated.

    ReplyDelete

Note: Only a member of this blog may post a comment.