Application Notes for Autodesk Building Systems

Monday, July 16, 2007 

CAD Tip of the Week: Attribute Macros

Topic: There are some ancient but nonetheless handy macros that help with attribute manipulation.

ATTRIBUTE MACROS

Attributes are variable text associated with blocks, containing for instance equipment or device tag strings. What is often inscrutable about attribute behavior is that each and every attribute is actually a separate entity (AutoCAD calls them 'subentities') from the linework comprising the rest of the block. Separate entities in that each and every attribute has its own layer, color, rotation angle, text style, text height etc. that are independent of the values assigned to the block's linework.

Access for editing attribute properties has never been easy. Many find it surprising that selecting a block and opening its properties dialog does NOT provide access to the attributes subentities.

The value of the attributes text string may be changed fairly simply now by double-clicking the block (it wasn't always so). However to change other attribute properties, you must type -ATTEDIT at the command line (don't forget the hyphen), then navigate a non-intuitive set of prompts that have remained essentially unchanged since the late 1980s to accomplish singular or global attribute property editing.

So the following macros are still useful for editing attribute properties. Many accept a selection set for input (as indicated by a 'Select objects:' prompt) and will automatically filter out any non-block entities before processing:

ATC - ATtribute Color Change attribute color
ATH - ATtribute Height Change attribute height
ATL - ATtribute Layer Change attribute layer
ATM - ATtribute Move Move attribute layer
ATS - ATtribute Style Change attribute text style
ATV - ATtribute zero-eleVate Zero attribute elevations
ATZ - ATtribute Zero-rotate Zero attribute rotations

TW - Text Width Change text & attribute width factor


Attribute Macro Code
Disclaimer: All code examples provided 'as-is'; no warranties or support options either expressed or implied!


(DEFUN C:ATM ( / E EN ENT A AN ANT LOOKING COUNT ICOUNT ITEMS )
; ATTRIBUTE MOVE
(COMMAND ".UNDO" "G")(SETQ E nil)
(SETQ LOOKING T)(SETQ COUNT 0)
(WHILE (NULL E)
(SETQ E (ENTSEL "\nSelect block: ")))
(SETQ EN (CAR E))
(SETQ ENT (ENTGET EN))
(IF (= (VAL 0 ENT) "INSERT")
(PROGN
(SETQ AN (ENTNEXT EN))
(SETQ ANT (ENTGET AN))
(WHILE LOOKING
(SETQ COUNT (+ COUNT 1))
(IF (/= (VAL 0 ANT) "ATTRIB")
(SETQ LOOKING nil))
(COND
((= (VAL 0 ANT) "ATTRIB") ; LOOK FOR ATTRIBUTES
(IF (= COUNT 1)
(PROGN
(PROMPT "\nMove attributes: ")
(COMMAND ".ATTEDIT" "" "" "" "" AN "P" PAUSE ""))
(PROGN
(PROMPT "\nNext attribute: ")
(COMMAND ".ATTEDIT" "" "" "" "" AN "P" PAUSE "")))
(SETQ AN (ENTNEXT AN))
(SETQ ANT (ENTGET AN)))
((= (VAL 0 ANT) "SEQEND")
(SETQ LOOKING nil)) ; END OF ATTRIBUTES -- STOP
(T (SETQ LOOKING nil))))) ; NO ATTRIBUTES
(PRINC "\nEntity is not a block..."))
(IF ANT (ENTUPD EN))(PRINC))

(DEFUN C:ATL ( / S1 D )
; STANDARDIZE ATTRIBUTES TO SPECIFIED LAYER
(COMMAND ".UNDO" "G")
(SETQ S1 nil) (GC) ; CLEAR SELECTION SET FOR USE.
(SETQ S1 (SSGET))
(IF (NULL LLY) (SETQ LLY (GETVAR "CLAYER")))
(SETQ D (STRCASE (GETSTRING (STRCAT "\nTarget layer <" LLY ">? "))))
(IF (/= 0 (STRLEN D)) (SETQ LLY D))
(ATL S1 LLY)(PRINC))

(DEFUN ATL ( S1 NLAY / D E EN ENT A AN ANT LOOKING COUNT ICOUNT ITEMS )
(SS-SIFT S1 0 "INSERT")
(SETQ ITEMS (SSLENGTH S1))
(SETQ ICOUNT 0)
(PROMPT (STRCAT "\n" (ITOA ITEMS) " block entities to process..."))
(PROMPT (STRCAT "\nProcessing block " (ITOA ICOUNT)))
(WHILE (<>? "))))
(IF (/= 0 (STRLEN D)) (SETQ LTS D))
(ATS S1 LTS)(PRINC))

(DEFUN ATS ( S1 NSTY / D E EN ENT A AN ANT LOOKING COUNT ICOUNT ITEMS )
(SS-SIFT S1 0 "INSERT")
(SETQ ITEMS (SSLENGTH S1))
(SETQ ICOUNT 0)
(PROMPT (STRCAT "\n" (ITOA ITEMS) " block entities to process..."))
(PROMPT (STRCAT "\nProcessing block " (ITOA ICOUNT)))
(WHILE (<>? ")))
(IF (/= nil D)(SETQ LTH D))
(ATH S1 LTH)(PRINC))

(DEFUN ATH ( S1 NHGT / D E EN ENT A AN ANT LOOKING COUNT ICOUNT ITEMS )
(SS-SIFT S1 0 "INSERT")
(SETQ ITEMS (SSLENGTH S1))
(SETQ ICOUNT 0)
(PROMPT (STRCAT "\n" (ITOA ITEMS) " block entities to process..."))
(PROMPT (STRCAT "\nProcessing block " (ITOA ICOUNT)))
(WHILE (<>? "))))
(IF (/= 0 (STRLEN D))
(SETQ LCR D))
(ATC S1 LCR)
(PRINC))

(DEFUN C:ATC ( / S1 D )
; STANDARDIZE ATTRIBUTES TO SPECIFIED COLOR
(COMMAND ".UNDO" "G")
(SETQ S1 nil) (GC) ; CLEAR SELECTION SET FOR USE.
(SETQ S1 (SSGET))
(IF (NULL LCR) (SETQ LCR (GETVAR "CECOLOR")))
(SETQ D (STRCASE (GETSTRING (STRCAT "\nNew color <" LCR ">? "))))
(IF (/= 0 (STRLEN D)) (SETQ LCR D))
(ATC S1 LCR)(PRINC))

(DEFUN ATC ( S1 NCOL / D E EN ENT A AN ANT LOOKING COUNT ICOUNT ITEMS )
(SS-SIFT S1 0 "INSERT")
(SETQ ITEMS (SSLENGTH S1))
(SETQ ICOUNT 0)
(PROMPT (STRCAT "\n" (ITOA ITEMS) " block entities to process..."))
(PROMPT (STRCAT "\nProcessing block " (ITOA ICOUNT)))
(WHILE (<> CNT 0)
(PROMPT (STRCAT "\rSifting entity " (ITOA CNT)))
(SETQ ELIST (ENTGET (SSNAME SS (SETQ CNT (1- CNT)))))
(COND
((/= (CDR (ASSOC CODE ELIST)) SCREEN)
(SSDEL (SSNAME SS CNT) SS))))
(PROMPT (STRCAT "\rSifting entity " (ITOA CNT) "...Done!"))
(PRINC))

(DEFUN SS-SIFT (SS CODE SCREEN)
(SETQ CNT (SSLENGTH SS))
(PROMPT (STRCAT "\nSifting entity " (ITOA CNT)))
(WHILE (> CNT 0)
(PROMPT (STRCAT "\rSifting entity " (ITOA CNT)))
(SETQ ELIST (ENTGET (SSNAME SS (SETQ CNT (1- CNT)))))
(COND
((/= (CDR (ASSOC CODE ELIST)) SCREEN)
(SSDEL (SSNAME SS CNT) SS))))
(PROMPT (STRCAT "\rSifting entity " (ITOA CNT) "...Done!"))
(PRINC))





Labels:


Comments: Post a Comment



<< Home