-
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.
-
Generic title block update tool - AutoCAD Electrical
March 10, 2009, 02:52 PM 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!

You must be logged in to post a comment.