Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting a single block using SSGET

8 REPLIES 8
Reply
Message 1 of 9
jamesloy22
1143 Views, 8 Replies

Selecting a single block using SSGET

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.

Tags (1)
8 REPLIES 8
Message 2 of 9
Moshe-A
in reply to: jamesloy22

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

 

 

 

Message 3 of 9
jamesloy22
in reply to: Moshe-A

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")?

Message 4 of 9
Moshe-A
in reply to: jamesloy22

yes you are right (my mistake)

 

it should be:

 

(setq ss (ssget "x" (list '(0 . "insert") '(2 . "car"))))

 

 

 

 

Message 5 of 9
jamesloy22
in reply to: Moshe-A

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

Message 6 of 9
Moshe-A
in reply to: jamesloy22

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

 

 

 

 

Message 7 of 9
jamesloy22
in reply to: Moshe-A

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.

Message 8 of 9
Moshe-A
in reply to: jamesloy22

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

 

 

Message 9 of 9
jamesloy22
in reply to: Moshe-A

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)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost