How to identify an object in AutoCAD drawing based on Entity Handle?

How to identify an object in AutoCAD drawing based on Entity Handle?

Anonymous
Not applicable
2,243 Views
8 Replies
Message 1 of 9

How to identify an object in AutoCAD drawing based on Entity Handle?

Anonymous
Not applicable

Hi

 

I have a DXF file of underground stormwater layout. Attached is the image.

 

Highlighted is the stormwater pipelineHighlighted is the stormwater pipeline

 

I ran python scripts to extract the geometry. It extracted geometry along with entity handles. 

 

My question is how can I zoom to highlighted area in the drawing based on entity handle? I am interested in the storm water pipe on Grey Street. How can I highlight just the stormwater pipe on Grey Street based on Entity Handle.

I tried (ENTGET(HANDENT"HandleID")), it displayed all the information but didn't highlight the any object in the drawing. 

or

Is it possible to find the entity handle in the drawing itself?

0 Likes
Accepted solutions (1)
2,244 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

Lets say the enget returns a "Line" so you would "zoom c pt scale to the mid point of the line. So you need a cond then say little defuns like 

 

 

(defun do-line (ent / )
(setq start (cdr (assoc 10 (entget ent))))
(setq end (cdr (assoc 11 (entget ent))))
(setq mp (mapcar '* (mapcar '+ start end) '(0.5 0.5)))
(command "zoom" "C" mp 100)
(princ)
)

 

It can vary what you do now with regards to the object.

0 Likes
Message 3 of 9

hmsilva
Mentor
Mentor

@Anonymous wrote:

...

I tried (ENTGET(HANDENT"HandleID")), it displayed all the information but didn't highlight the any object in the drawing. 

or

Is it possible to find the entity handle in the drawing itself?


Try

 

(cond ((setq ent (handent HandleID))
       (command "_zoom" "_O" ent "")
       (redraw ent 3)
      )
      (T (princ "\nHandle not used by any entity in the current drawing..."))
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 9

dgorsman
Consultant
Consultant

In relation to the other posts, the (enget ...) function returns a list of dotted pairs with information about the provided entity.  It doesn't zoom, select, or do anything on the UI side.  It's up to the rest of the LISP code to do things with that data (in this case, nothing at all - the entity code returned from the (handent ...) call can be passed to a call to the ZOOM command).

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 5 of 9

Anonymous
Not applicable

Thanks for your reply.

I have a basic question. I am new to AutoCAD and AutoLISP programming.

I executed (ENTGET(HANDENT "HandleId")) in autocad command line. To execute the code you mentioned, I opened Visual Lisp editor from Autocad and tried your code in Visual Studio Code text editor. I ran the code and it is opening a new AutoCAD window but didn't zoom any object in the already opened drawing. How can I link my Visual Studio Code to AutoCAD? I did search few videos and they were in visual lisp and there is a tab load function. I couldn't see that in Visual Studio Code text editor. 

Please help me if there are any videos explaining how to link Visual Studio Code editor to AutoCAD?

 

Thanks

Shilpa 

0 Likes
Message 6 of 9

Sea-Haven
Mentor
Mentor

hmsilva answered your request at simplest

 

(command "_zoom" "_O" (handent HandleID))

0 Likes
Message 7 of 9

Anonymous
Not applicable

Attached  is the DXF file of a stormwater line. The python program extracted the geometry into a csv file (attached). There are number of objects in "PDF_Stormwater Pipe As Con" layer with different entity handles. 

What is the best approach to find the entity handle of stormwater line highighted in blue in the drawing?

0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

(setq hand (cdr (assoc 5 (entget (car (entsel "\nPick object "))))))

0 Likes
Message 9 of 9

john.uhden
Mentor
Mentor
Accepted solution

I almost always like to apply cold grips to entities selected programatically...

(sssetfirst nil (ssadd (handent handle)))

That way they are not only pretty easily seen but also selected.

John F. Uhden

0 Likes