;;--------------------------------------------------------------------- ;; ;; PointA 2003 Wizard Lab Utility Set by Bill Kramer ;; Attribute manipulations ;; ;; ATT_GetAll - returns a list of attributes for an entity ;; ;;--------------------------------------------------------------------- ;; ;; Attributes List Structure is: ;; (( . ) ( . ) ... ( . )) ;; (defun ATT_GetAll (EN ; Entity name / EL ; Entity data list RES ; Result list ) (setq EN (entnext EN) ;EN is insert object, move to attributes EL (entget EN) ;get first attribute ) (while (= (cdr (assoc 0 EL)) ;Loop while EL has an attribute object "ATTRIB") (setq RES ;Build result list by (cons ;adding (cons ;a dotted pair containing (cdr (assoc 2 EL)) ;the tag and (cdr (assoc 1 EL))) ;the value RES ;to the front of the result list. ) EN (entnext EN) ;get next entity in chain EL (if EN (entget EN) ;get its entity list '((0 . "END")))) ;or set to end ) ;end WHILE loop (reverse RES) ;return reversed result list ) ;;--------------------------------------------------------------------- ;; Retrieve an attribute given the entity name and tag string. ;; (defun ATT_GetOne (EN ;entity name of insert object TAG ;tag name of attribute you want / EL ;entity data list ) (setq EN (entnext EN) ;move past the insert object EL (entget EN) ;and get the entity object data list ) (while (and ;loop while entity object in EL (= (cdr (assoc 0 EL)) "ATTRIB") ;is an attribute and (/= (cdr (assoc 2 EL)) TAG) ;does not have a matching tag ) (setq EN (entnext EN) ;get the next entity object EL (entget EN) ;get the next entity data list ) ) (if (= (cdr (assoc 0 EL)) "ATTRIB") ;did we find one? (cdr (assoc 1 EL)) ;yes, return the value ) ;else nil is the result. ) ;;--------------------------------------------------------------------- ;; ;; ATT_SSGet - Builds a selection set of all inserts that have a given ;; tag name. ;; (defun ATT_SSGet (TAG ;tag name / SS1 ;search selection set SS2 ;resulting selection set CNT ;integer counter EL ;entity data list ) (setq SS1 ;build selection set (ssget "X" ;by looking at each object '((0 . "INSERT") ;for INSERT objects (66 . 1)))) ;with attributes. (if SS1 ;If we found blocks with attributes (progn (setq CNT 0 ;start a counter SS2 (ssadd) ;and create a new selection set ) (repeat (sslength SS1) ;Loop through selection set one (if (ATT_GetOne (ssname SS1 CNT) TAG) ;is tag there? (ssadd (ssname SS1 CNT) SS2) ;yes so add it to result set ) (setq CNT (1+ CNT)) ;increment the counter ) )) SS2 ;return the resulting set ) ;;--------------------------------------------------------------------- ;; (defun ATT_PutOne (EN ;entity name TAG ;tag name NEW ;new value / EL ;entity data list ) (setq EN (entnext EN) ;move to next entity object EL (entget EN) ;and get the entity list ) (while (and ;loop while EL is an (= (cdr (assoc 0 EL)) "ATTRIB") ;attribute and (/= (cdr (assoc 2 EL)) TAG) ;is not the tag we seek ) (setq EN (entnext EN) ;get the next entity object EL (entget EN) ;get the entity data list ) ) (if (= (cdr (assoc 0 EL)) "ATTRIB") ;attribute found? (progn (entmod ;change the entity (subst ;substituting the (cons 1 NEW) ;new value with (assoc 1 EL) ;the old value EL)) ;in the entity list (entupd EN) ;update display for nested entity ) ;end PROGN ) ;end IF ) ;;--------------------------------------------------------------------- ;; (defun ATT_PutAll (EN ;entity name AL ;attribute nested list / EL ) (setq EN (entnext EN) ;get the next entity object EL (entget EN) ;and the data list ) (while (= (cdr (assoc 0 EL)) "ATTRIB") ;loop while attribute (if (assoc (cdr (assoc 2 EL)) AL) ;tag matches member of list? (entmod (subst (cons 1 (cdr (assoc (cdr (assoc 2 EL)) AL))) (assoc 1 EL) EL)) ) (setq EN (entnext EN) ;get the next entity object EL (entget EN) ;and the data list ) ) ;end WHILE (if (= (cdr (assoc 0 EL)) "SEQEND") ;end of attributes (entupd ;update entity object display of INSERT object (cdr (assoc -2 EL))) ) )