-
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.
-
Adding a special cross-ref capability to AutoCAD Electrical
March 24, 2009 02:26 PMby Nate HoltCross-reference a schematic parent symbol onto a panel footprint or panel terminal representation. Not supported out-of-the-box, but you can create your own tool to do it!
This issue was raised by a user who was using AutoCAD Electrical to do instrumentation-type drawings - dealing with junction box wiring diagrams. He wanted to show the terminal strip components as panel terminal symbols but then show a sheet / zone cross-reference text on each panel terminal pointing back at its schematic representation.
AutoCAD Electrical currently has no provision for pushing cross-reference annotation on to panel footprint or panel terminal symbols. But, when "surfing", the surf window shows both schematic and panel references in its little window. So, the data is available, it's just not being exploited in this particular situation.
Here's a little utility that may do the job. You pick on panl footprint and panel terminal representations. The utility uses an internal call that the "Surfer" command normally calls. The returned data is parsed to pull out the schematic parent or schematic terminal sheet and zone (line reference) value. Data is then pushed to the picked panel footprint - result is that the panel symbol now carries a reference back to its schematic representation!
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 here: files/25201_25300/25241/file_25241.lsp and rename panel_crossref.lsp
To use:
1. You need to add attribute XREF to your panel symbol or panel terminal
2. APPLOAD attached. Type PANEL_CROSSREF [Enter]. Pick on panel footprint or panel terminal symbols.
-
Generic title block update tool - AutoCAD Electrical
March 10, 2009 02:52 PMby Nate HoltLate night email from user- need to change text width of one attributed text entity. Buried in title block used on hundreds of drawings. Help! Now! Please!
No problem. Here's a generic attribute search/rescue utility... download it, APPLOAD it, and you've got it. Its syntax is
(attrib_resize blockname attrname textheight textwidth )
where:
blockname = target block name to find on each drawing (can be wild-carded)
attrname = attribute tag name to find on the target block (can also be wild-carded)
textheight = new text height (set to nil for no change)
textwidth = new text width factor (set to nil for no change)
How it Works
Here's the little AutoLISP program, "attrib_resize", along with its the four passed arguments shown above. The program flow is this:
Step 1 - create a selection set of all block instances (entity type "INSERT") that wild-card match the passed "blockname".
Step 2 - if any found, process them one at a time. Open each block insert and cycle through it. Process each "ATTRIB" entity contained within this block instance.
Step 3 - if find ATTRIB entity that wild-card matches with attrname then adjust the textheight and/or textwidth values
Step 4 - write new data back to the attribute entity and force it to update, loop back around until all attributes processed in this block insert instance. Then loop back up to top to process next block instance found on drawing (if there are any more).
Finally - when no more target blocks found on active drawing, exit the utility.
(defun attrib_resize ( blockname attrname texthgt textwidth / ss slen
block_en ix enn edd)
; PURPOSE - modify attribute height and/or width of target attribute name
; on all instances of block "blockname" on active drawing.
; "blockname" = target blockname, wild-cards okay
; "attrname" = target attribute name, wild-cards okay
; texthgt = new height (nil=do not adjust existing height)
; textwidth = new width factor (nil=do not adjust existing width)
(if (AND blockname attrname)
(progn
(if (AND texthgt (= (type texthgt) 'STR))(setq texthgt (atof texthgt)))
(if (AND textwidth (= (type textwidth) 'STR))(setq textwidth (atof textwidth))); STEP 1
; Create selection set of all block instances on active drawing
; that wild-card match "blockname" argument.
(setq ss (ssget "_X" (list (cons -4 "<AND")
(cons 0 "INSERT")
(cons 2 blockname)
(cons -4 "AND>"))))
(if (/= ss nil)
(progn ; one or more instances of target block found
(setq slen (sslength ss)) ; number of instances
(setq ix 0) ; index pointer
(while (< ix slen); STEP 2
(setq block_en (ssname ss ix))
(setq ix (1+ ix)) ; increment pointer for next time
; Cycle through block instance, look for target attribute
(if (setq enn (entnext block_en)) (setq edd (entget enn)))
(while (AND enn (/= (cdr (assoc 0 edd)) "SEQEND")
(/= (cdr (assoc 0 edd)) "INSERT") ); STEP 3
(if (AND (= (cdr (assoc 0 edd)) "ATTRIB")
(wcmatch (cdr (assoc 2 edd)) attrname))
(progn ; Found instance of target attribute; STEP 4
(if texthgt
(progn ; adjust text height
(setq edd (subst (cons 40 texthgt)(assoc 40 edd) edd))
) )
(if textwidth
(progn ; adjust text width
(setq edd (subst (cons 41 textwidth)(assoc 41 edd) edd))
) )
(if edd
(progn
(entmod edd) ; write new data back to attribute
(entupd enn)
) ) ) )
; Advance to next subentity in this block insert instance
(if (setq enn (entnext enn)) (setq edd (entget enn)))
)
) ) ) ) )
(princ)
)Download this Utility
Find it here: files/24801_24900/24881/file_24881.lsp . Rename it attrib_resize.lsp and save it to some folder that is in your ACAD path.
How to Use?
Let's say that you have 500 drawings that need to have the title block's SCALE attribute width set to 0.85 but leave the attribute's existing text height unchanged. The title block's block name is "acade_title".
The call to make this happen, per drawing, is this:
(attrib_resize "acade_title" "SCALE" nil 0.85)
We just need to open up each of the 500 drawings and issue the above command ( ! ).
There are two automated ways built in to AutoCAD Electrical.
Option 1 - The easiest way is to do a trick with the "Modify Symbol Library" tool. This works only if all the drawings you want to process are in their own folder. Let's say all 500 drawings are in folder "c:\temp\". Make sure you're in SDI mode (with only one drawing active on screen, type SDI [Enter] at "Command:" prompt. Set value to 1. Then APPLOAD the above AutoLISP utility. Now launch the AutoCAD Electrical "Modify Symbol Library" utility, enter as shown below, and hit "START".

Option 2 - You want to process drawings defined in the active project using AutoCAD Electrical's "Project Wide Utilities" tool. First step is to create a small script file, let's say QUICK_FIX.SCR, with these lines in it:
(load "attrib_resize.lsp")
(attrib_resize "acade_title" "SCALE" nil 0.85)
qsaveNow launch the Project-Wide Utilities tool and make selection as shown here. Hit OK and off you go!

-
Importing Wire Types from a master schematic - AutoCAD Electrical
March 3, 2009 12:33 PMby Nate Holt
Autodesk's Yook-Mei Chong came up with a cool utility for ACE2009 to automate a sometimes-tedious schematic set-up task!
Let's say you're creating a new schematic drawing to add to an existing AutoCAD Electrical project. It is going to be similar in function to an existing drawing where you've set up a number of custom "wire types". What you'd like to do is just pull all of those wire types over to your new drawing and get moving.
What Mei has done is create a cool little AutoLISP utiltiy to do this. Her utility prompts you to browse to the target "source" drawing. It reads the existing wire types on that drawing and re-creates them in the active drawing.
She also created a project-wide version of this utility. You browse to the target "source" drawing that has the set of desired wire types defined. The utility then pushes these out to all of the selected drawings in the active AutoCAD Electrical project. Seems to work well [but use at your own risk!!].
You can download this utilty here: files/24701_24800/24761/file_24761.lsp and rename it copywiretype.lsp.
To use:
Download and APPLOAD the above file
Then, to pull a set of wire types to the active drawing...
1. Type COPY_WT [Enter] at command line.
2. Browse to the target "source" drawing that carries the desired wire types.
Or, to pull a set of wire types into all selected dwgs of the active project...
1. Type COPY_WT_PROJ [Enter] at command line.
2. Browse to the target "source" drawing that carries the desired wire types.
3. Select the drawings in the active project that are to be updated with these new wire types. Hit OK.
This utility is just a plain AutoLISP tool that makes some calls into the AutoCAD Electrical "API". Please feel free to modify / enhance it. For example, maybe you want to add an option to only pull in certain wire types. Or perhaps you want it to list the available wire types and then you select which ones to pull in. Use your imagination!