PDA

View Full Version : how to grab and modify enities within a block



clintonc
2004-09-01, 07:54 PM
how do I search thru the parts of a block.

RobertB
2004-09-01, 08:43 PM
(entnext) or (vla-Item)

peter
2004-09-01, 09:15 PM
Here is a simple example of iterating through a block definition and printing the object names of the objects in the block.

Peter Jamtgaard



(defun C:blky (/ colBlock strBlockName)
(while (not (setq lstSelection (entsel "\nSelect Block :")))
(princ "\nSelect Again: ")
)
(setq strBlockName (cdr (assoc 2 (entget (car lstSelection))))
colBlock (vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
strBlockName
)
)
(vlax-for objBlock colBlock
(princ "\n")
(princ (vla-get-objectname objBlock))
(princ "\n")
)
)

stig.madsen
2004-09-01, 09:30 PM
And in good ol' AutoLISP:


(defun blockWalk (bname / a ent)
(and (setq a 0 ent (cdr (assoc -2 (tblsearch "BLOCK" bname))))
(while ent
(princ (cdr (assoc 0 (entget ent))))
(terpri)
(setq ent (entnext ent) a (1+ a))
)
(princ (strcat (itoa a) " objects in " bname))
)
(princ)
)

The engine is ENTNEXT, as Robert pointed out. It requires some more code if it's not supposed to return subents from subents, though. Peter's example only returns subents within the block.