-
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.
-
Mass update - attribute re-namer tool - AutoCAD Electrical
May 20, 2009, 10:32 PM Nate HoltThis came up recently. It's not a perfect solution but seemed to make the user happy. He had a number of old schematic designs made with generic blocks with attributes. He wanted some AutoCAD Electrical compatibility for simple things like BOM reporting.
The key is to rename the attributes to be those that AutoCAD Electrical expects to find. Here is a utility that seems to work. It process all block inserts on the active drawing. For each block it scans the block for all its attributes. It compares each attribute to a list of "old" names. On a match it gets the corresponding new name and renames the attribute on-the-fly.
Seems to work!
This AutoLISP program is reproduced here. The old versus new attribute name list is in the top part of the program. Edit this file and replace the old/new attributes appropriately. Save the file, APPLOAD it, and run it!
; 20-May-09 NEHolt created
(defun c:attr_rename_list ( / x_en enn edd ss slen ix atnam
namelist hit blk_ent
matchname newed x)
; Process all block instances on active drawing. Check each
; attribute for match on first element in list below. On any
; match, rename the attribute to the new name given in the
; second element.
; *********** ATTRIBUTE OLD versus NEW names list ******************
(setq namelist (list
; list old name and new name. Old name can contain wild cards.
(list "ID" "TAG1") ; list old name and new name.
(list "TEXT-1" "DESC1")
(list "TEXT-2" "DESC2")
(list "TERMINAL1" "TERM01")
(list "TERMINAL2" "TERM02")
(list "PARTNUM" "CAT")
(list "VENDOR" "MFG")
) )
; **********************************************************************
; Extract selection set of all block inserts on active drawing
(setq ss (ssget "_X" '((0 . "INSERT"))))
(if (/= ss nil)
(progn
(setq slen (sslength ss))
(setq ix 0)
(while (< ix slen)
(setq blk_ent (ssname ss ix)) ; get next block insert to process
(setq ix (1+ ix)) ; increment for next time
(setq enn (entnext blk_ent))
(setq edd (entget enn))
(while (AND enn (/= (cdr (assoc 0 edd)) "SEQEND")
(/= (cdr (assoc 0 edd)) "INSERT") )
(if (= (cdr (assoc 0 edd)) "ATTRIB")
(progn
(setq atnam (cdr (assoc 2 edd)))
(setq hit nil)
(foreach x namelist
(if (not hit)
(progn ; no match yet, keep processing
(setq matchname (car x))
(if (wcmatch atnam matchname)
(progn ; found exact match or wild-card match
; Change name now. Substitute in new name.
(setq newed (subst (cons 2 (cadr x)) (assoc 2 edd) edd))
(entmod newed) ; update the title block instance
(entupd blk_ent)
(princ "\n")
(princ atnam)
(princ " --> ")
(princ (cadr x))
(setq hit 1) ; flag that found
) ) ) )
)
)
)
; go to next sub ent in block instance and loop back up
(if (setq enn (entnext enn)) (setq edd (entget enn)))
) )
(setq ss nil) ; release the selection set
)
)
(princ) ; prettier
)Download a copy of the utility here: files/27801_27900/27811/file_27811.lsp
Rename it to something like attr_rename_list.lsp. Then to run it, APPLOAD this file and type attr_rename_list [Enter] at the AutoCAD command prompt.
Comments
-
May 21, 2009 06:30 PM Timothy Willey
Maybe it should be noted that this will only change the blocks that are inserted already. If a new block is inserted it will have the old attribute information.
You must be logged in to post a comment.