I am fairly new to LISP writing and I had a basic question. If I have a drawing with multiple blocks of the same name, let's say all my blocks are the "CAR" block that are completely identical, I need a way to find the entity names of each individual block in the DWG. Once I have this information, I need to build a selection set so where I can select only one of the blocks to manipulate using that entity name as criteria. Is this possible?
Thanks.
James Hi,
try this:-
(defun C:GrabCars (/ ss i ename elist ;| declare local variables|; ) (if (setq ss (ssget "x" (list '(0 . "CAR")))) ; select all CAR inserts automaticlly (progn (setq i -1) ; set an index (repeat (sslength ss) ; loops through entitys (setq i (1+ i) ; inc index ename (ssname ss i) ; get entity ename elist (entget ename) ; get entity database ) (setq elist (subst (cons '8 "0") (assoc '8 elist) elist)) ; change entity to layer 0 (entmod elist); update database ); repeat ); progn ); if (princ) ; quiet exit ); C:GrabCars
cheers
moshe
I just ran the lisp and I can't tell if it is doing anything... is your first selection set correct or do you need to select (0 . "Insert")?
yes you are right (my mistake)
it should be:
(setq ss (ssget "x" (list '(0 . "insert") '(2 . "car"))))
That fixed the lisp but it is just changing the layer back to 0 for all my blocks... I need a way to display what their entity name or entity handle is and then use that information in a seperate selection set. Any ideas?
James
James,
i changed the block references (insert) to layer 0 just to show you how you can use the entity database to modify entity
(setq elist (subst (cons '8 "0") (assoc '8 elist) elist))
the entity name is in ename variable
(setq i (1+ i) ; inc index
ename (ssname ss i) ; get entity ename
elist (entget ename) ; get entity database
)
if you want to display it? add these lines to the code
(terpri)
(princ ename)
Moshe
Your code works but it seems like the entity name changes everytime you open and close your drawing... is there another property you can access that does not constantly change like entity name? I was reading something about handles but I did not understand them very well.
Thanks.
James,
i still do not understand what you are trying to do?
yes it's true the entity name are build from start each time you open the drawing
elist (entity database) contains handle of the entity which is in HEX decimal (a string type)
you can retrieve it with (handent) function
(setq hnd (cdr (assoc '5 elist))) ; get handle
(handent hnd) ; returns entity ename
handles are fix for the life time of entity. as far as i know you can't use handles to modify an entity...you need to get it's ename
Moshe
I want to be able to write a .lsp that consistantly grabs a single block handle (which is known and hard coded into the .lsp file itself) and changes the properties of that single block. What I am not sure is if you need to write a lisp that first associates the known handle to find the corresponding entity name assigned to that particular block during that session of CAD in order to change the property of that block.
(Note: I know my desired lisp sounds pointless but bear with me... its part of a bigger code)