;;;UTILITY SUBROUTINE
;;;------------------------------------------------------------------------------------------------
;;;Thanks to J. Roper for this section:
;;---------------------------------------------------------
;ATT:GETS - Utility routine to get all attributes for
;an insert object (EN).
;;
;;You pass this function an entity name, like something that would be returned from this example:
;;(setq EN (car (entsel "\nSelect block")))
;;an entity name looks like this when returned on a command line --><Entity name: 4119ab90>
;;You use this function like this: (setq ATTLIST (ATT:GETS EN))
;;it returns a list like this ---> (("TAG1 . "VALUE1")("TAG2" . "VALUE2")....)
(defun ATT:GETS
(EN
/ EL RES
) ;entnext goes on to the next entity. If what you passed is an attributed block, the next entity will be an attribute.
EL
(entget EN
));entget "breaks open" the entity name to reveal the entity list (while (= "ATTRIB" (cdr (assoc 0 EL
)));we check the entity list to see if it is an attribute (cons (cdr (assoc 2 EL
));if it is, we create a list of its tag and value, dxf code 2 and 1, using CONS EN
(entnext EN
);go to the next entity EL
(entget EN
)));get the next entities list (reverse RES
);reverse the list to put it in proper order. )
;;;MAIN SUBROUTINE
;;;Returns a list of all tags, from all blocks, with the name within variable "NestedLookForName"
(defun FINDNESTEDTAGS
(NestedLookForName
) ;;;sub routine to get tag info. Returns formatted tag info.
(defun ProcessTags
(ent
/ 1stAtt TagAtts TagList
) ;checks to see if tag is an equipment tag.
(if (= "ITEM#" (caar (ATT:GETS ent
))) ;if so, then process to get tag attributes
;if not, then process the other type of tag for it's attributes
;get tag number
;get tag type and string it together with the tag number
(cond; this section just puts the number attributes to 3 digits dot two digits, i.e. change 0.00 & 00.00 to 000.00 (T 1stAtt)
);cond
);strcat
);setq
);progn
);if
TagAtts
);defun
;;get a selection set of all blocks
SelectedEntity nil
SelectedEntityCodes nil
BlockDefinition nil
NestedEntity nil
NestedEntityCodes nil
TagList nil)
;;start to loop through selection set (entities will get deleted from seletion set each round)
;check to see if entity is a tag block
(= NestedLookForName
(cdr (assoc 2 SelectedEntityCodes
))) );and
;if so, process tag block in selection set
(setq TagAtts
(ProcessTags SelectedEntity
) TagList
(cons TagAtts TagList
)) ;if not, process for nested blocks
;find blocks within the first block in the selection set
;get dxf code -2 for nested blocks
;loop through internal entities of block
;get codes of internal entity
;check to make sure internal entity is a block, has correct name, has attributtes and is visible
(= NestedLookForName
(cdr (assoc 2 NestedEntityCodes
))) (= (cdr (assoc 66 NestedEntityCodes
)) 1) (/= 1 (cdr (assoc 60 NestedEntityCodes
))) );and
;if ok, then process internal entity
(setq TagAtts
(ProcessTags NestedEntity
) TagList
(cons TagAtts TagList
) NestedEntity
(entnext NestedEntity
)) );if
);while
);progn processing nested entities
);if checking for tag in selection set
;remove entity from selection set
(ssdel SelectedEntity sset
) );while processing selectionset
TagList
);defun
;;;test function to get tags
(defun c:test6
() (setq Allblocks
(FINDNESTEDTAGS
"ERINTAG")))