Entity name list

Entity name list

carlos_m_gil_p
Advocate Advocate
5,562 Views
22 Replies
Message 1 of 23

Entity name list

carlos_m_gil_p
Advocate
Advocate

Hello how are you.

Someone will have a recursive function to extract the name of all the entities that are in a drawing.

I need to get a list in this way, to place it in a dcl.

("ARC" "CIRCLE" "LINE" "POLYGONMESH")

I selected everything that is in the drawing, then I extract the name of each entity and if it works for me.

But the problem is that if I have many entities, the function gives an error.

And the only way to solve it is with a recursive function.

Or if there is another way to get that list from the database directly. That would be good.

Thank you very much.

And excuse me my English, I only speak Spanish.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Accepted solutions (1)
5,563 Views
22 Replies
Replies (22)
Message 2 of 23

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:

 

But the problem is that if I have many entities, the function gives an error...


What error are you getting from the function?


And the only way to solve it is with a recursive function.Or if there is another way to get that list from the database directly. That would be good.

 


Yes, there is another way but of what?

 

Post the error message here and the list that is causing the error.

 

0 Likes
Message 3 of 23

stevor
Collaborator
Collaborator
And post the DCL code, with the Autolisp code.
S
0 Likes
Message 4 of 23

carlos_m_gil_p
Advocate
Advocate

Hi, thank you for help me.

 

this is the error.

 

Hard error occurred ***
internal stack limit reached (simulated)

 

this is code lisp

 

(vl-load-com)

;;; Quick select person

(defun c:xxx  (/)
  (setq all (ssget "_X"))
  (setq lst-org nil)
  (setq lst-org-f nil)
  (setq i -1)
  (while (setq ent-uni (ssname all (setq i (1+ i))))
    (setq lst-org (cons (substr (vla-get-objectname (vlax-ename->vla-object ent-uni)) 5) lst-org)))
  (setq lst-org-f (acad_strlsort (reduce-conjunto lst-org)))
  (cmd-dcl))

;;; Elimina atomos repetidos de una lista
;;; Por Jose A. Alonso Jimenez
;;; jalonso@us.es

(defun reduce-conjunto  (l)
  (cond ((atom l) l)
        ((member (car l) (cdr l)) (reduce-conjunto (cdr l)))
        (t (cons (reduce-conjunto (car l)) (reduce-conjunto (cdr l))))))

;;; Ejecucion del cuadro DCL

(defun cmd-dcl  (/)
  (setq dcl_id (load_dialog "SelectObj.DCL"))
  (new_dialog "SelectObj" dcl_id)
  (start_list "txtobjorg" 3)
  (mapcar 'add_list lst-org-f)
  (end_list)
  (start_dialog)
  (unload_dialog dcl_id))

 

and this is code dcl

 

 

SelectObj : dialog
	{label="  Entidades";
	spacer;
	spacer;
		:row {
			:boxed_column {
				label=" Object type: ";
					:list_box {
						key="txtobjorg";
						is_enabled = true;
						width=18;
						height=13;
						}
						spacer;
					}
			}
			spacer;
		:row {
			:button {
				key="canselobj";
				label="Cancel";
				is_default=true;
				}
		}
		spacer;
	}

 

this is dwg 10 mb

 

https://drive.google.com/open?id=1uMtWp8mTGTpH6rC2Mj1pcCy91sdWV-63

 

This code lisp is very slow when there are many entities.

 

escuse me my english I only speak enlish

 

Thank you.

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 5 of 23

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:

Hi, thank you for help me.

 

this is the error.

 

Hard error occurred ***
internal stack limit reached (simulated)

 

this is dwg 10 mb..

 

 


That is one big file you got there 

 

instead of removing duplicates, filter the list while iterating through the selection

 

Your code with filters.

 

 

(defun c:xxx  (/ all lst-org lst-org-f ent-uni i objectype )
  (setq all (ssget "_X" '((0 . "ARC,CIRCLE,LINE,POLYGONMESH")(410 . "Model")(8 .  "~MARCO"))))
  (setq lst-org nil)
  (setq lst-org-f nil)
  (setq i -1)
  (while (setq ent-uni (ssname all (setq i (1+ i))))
    (Setq objectType (substr (vla-get-objectname (vlax-ename->vla-object ent-uni)) 5))
    (if (not (member objectType lst-org))
		(setq lst-org (cons objectType lst-org)))
    )
  (setq lst-org-f (acad_strlsort lst-org))
  (cmd-dcl))

No conversion to vla-object  

 

  (while (setq ent-uni (ssname all (setq i (1+ i))))
    (Setq objectType (cdr (assoc 0 (entget ent-uni))))
    (if (not (member objectType lst-org))
		(setq lst-org (cons objectType lst-org)))
    )

 

HTH

 

BTW: What are you planning to do with the list anyway?

 

 

0 Likes
Message 6 of 23

carlos_m_gil_p
Advocate
Advocate


Thanks for your help brother, it works very well.

 

I want to create a command similar to quick select.
But that I can select the entities that I need and delete them directly.
I can not do a filter with ssget.
Because I need to know all the entities that are in the drawing.
I use the conversion to vla-object to give me the correct name of the entity.
Because if not, you would have to do the comparison of objects when you use the same name.
For example, if there is a POLYLINE entity, I would take the polyline, 2d polyline and the polygonmesh.
And I need these entities to be separated in the list.

How could you separate those entities in the list?

 

If I convert entities to vl-object it is very slow.

 

Thank you.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 7 of 23

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:


Thanks for your help brother, it works very well.

 

 the polyline, 2d polyline and the polygonmesh.
And I need these entities to be separated in the list.

How could you separate those entities in the list?

 

Thank you.


On the sample you posted, i run the program without the filter and I get this.

 

 

carlos.png 

 

and still not using vl conversion.

 

(defun c:xxx  (/ all lst-org lst-org-f i )
  (setq all (ssget "_X" ))
  (setq lst-org nil)
  (setq lst-org-f nil)
  (setq i -1)
  (while (setq ent-uni (ssname all (setq i (1+ i))))
    (Setq objectType (cdr (assoc 0 (entget ent-uni))))
    (if (not (member objectType lst-org))
		(setq lst-org (cons objectType lst-org)))
    )
  (setq lst-org-f (acad_strlsort lst-org))
  (cmd-dcl))

Is that what you're after?

 

0 Likes
Message 8 of 23

carlos_m_gil_p
Advocate
Advocate

Hi brother.

Without a doubt, that is the best way.

But I want the list to appear like this.

Thank you.I want to.jpg

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 9 of 23

pbejse
Mentor
Mentor

 

(defun c:xxx  (/ all lst-org lst-org-f i )
  (setq all (ssget "_X" ))
  (setq lst-org nil)
  (setq lst-org-f nil)
  (setq i -1)
  (while (setq ent-uni (ssname all (setq i (1+ i))))
    (setq entDAta (entget ent-uni))
    (Setq objectType (substr  (cdr
		       (assoc 100 (member (assoc 410 entDAta) entDAta))) 5))
    (if (not (member objectType lst-org))
		(setq lst-org (cons objectType lst-org)))
    )
  (setq lst-org-f (acad_strlsort lst-org))
  (cmd-dcl))

 

0 Likes
Message 10 of 23

carlos_m_gil_p
Advocate
Advocate

Hi brother.

It works much better.
But entities like arc do not appear in the list.

Thank you.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 11 of 23

pbejse
Mentor
Mentor
Accepted solution

Ooops ... 

 

It is missing the Arc object Smiley Very Happy..Hang on...

 

EDIT: Ha! you notice that too.. BRB

 

with limited testing, reversing the entity data list should work

 

(defun c:xxx (/ all lst-org lst-org-f i )
  (setq all (ssget "_X"))
  (setq lst-org nil)
  (setq lst-org-f nil)
  (setq i -1)
  (while (setq ent-uni (ssname all (setq i (1+ i))))
    (Setq objectType (substr (Cdr (assoc 100 (reverse (entget ent-uni)))) 5))
    
    (if (not (member objectType lst-org))
		(setq lst-org (cons objectType lst-org)))
    )
  (setq lst-org-f (acad_strlsort lst-org))
  (cmd-dcl))
0 Likes
Message 12 of 23

carlos_m_gil_p
Advocate
Advocate

Brother, it works better.

I attached a new file with entities.
It can be compared with those of the qselect command and there are some that do not appear.
Why does that happen?
Like polar array, center mark, among others. They are some of those that do not appear.


Thank you.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 13 of 23

john.uhden
Mentor
Mentor

 

This will return a list of all the entity types in the drawing:

(defun @etypes ( / ss i etype etypes)   (and     (setq ss (ssget "X"))     (repeat (setq i (sslength ss))       (setq etype (cdr (assoc 0 (entget (ssname ss (setq i (1- i)))))))       (or (vl-position etype etypes)(setq etypes (cons etype etypes)))     )   )   etypes ) 

 

John F. Uhden

Message 14 of 23

carlos_m_gil_p
Advocate
Advocate

Hello john.uhden, how are you?
Thanks for your contribution.


I am testing your function, but it is less specific.
If you notice, when you apply it, it returns this:

 

("VIEWPORT" "TEXT" "ACAD_TABLE" "NURBSURFACE" "LOFTEDSURFACE" "3DFACE" "MULTILEADER" "MTEXT" "MLINE" "MESH" "LEADER" "HELIX" "HATCH" "LWPOLYLINE" "ELLIPSE" "CIRCLE" "LINE" "ATTDEF" "SPLINE" "INSERT" "ARC" "3DSOLID" "ARC_DIMENSION" "DIMENSION" "POLYLINE")

With the function of pbejse it is more specific.
Returns the list as follows:

 

("2dPolyline" "2LineAngularDimension" "3dPolyline" "3dSolid" "3PointAngularDimension" "AlignedDimension" "Arc" "ArcDimension" "AttributeDefinition" "BlockReference" "Circle" "DiametricDimension" "Ellipse" "Face" "Hatch" "Helix" "Leader" "Line" "LoftedSurface" "MLeader" "Mline" "MText" "NurbSurface" "PolyFaceMesh" "PolygonMesh" "Polyline" "RadialDimension" "RotatedDimension" "Spline" "SubDMesh" "Table" "Text" "Viewport")

The doubt is that when looking at what the qselect command returns, there are entities that are not there.
I think I'm going to have to do a comparison of entity by entity.

Another thing they told me, is that I use (entnext) and not (ssget).
But I do not know how to apply the (entnext)

Do you know something about how it could be used?

Thank you.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 15 of 23

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:

It can be compared with those of the qselect command and there are some that do not appear.


What would be the main function of this routine carlos? 

 

 

0 Likes
Message 16 of 23

carlos_m_gil_p
Advocate
Advocate

Hi brother.
The purpose is to make a selection of several entities at once and delete them or use them for later use.

I will continue polishing the list.
But already with the new function yours is faster and does not give me error.

Thank you very much.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 17 of 23

john.uhden
Mentor
Mentor

Yes, PBGV is very astute.  The difference is that he used the ObjectName property of each vla-object, whereas I used what (entget) returns.

The former is probably better as it differentiates 3D polylines from meshes from heavy 2D polylines, etc.

 

The use of entnext will include subentities such as vertices and attributes and seqends, and is likely to be much much slower.

John F. Uhden

0 Likes
Message 18 of 23

carlos_m_gil_p
Advocate
Advocate

Hello john.uhden how are you.

You are absolutely right, with vla-object all the entities come out separately.
But there are some that do not appear.

Thanks for explaining me about the entnext.
If I realized when I was doing tests.
And I saw that they use it to count entities, but I do not understand why to count if it works and to get the names of the entities not. 🙂

Greetings.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 19 of 23

john.uhden
Mentor
Mentor

@carlos_m_gil_p wrote, "But there are some [entity names] that do not appear."

 

Like what do you suspect is missing?

John F. Uhden

0 Likes
Message 20 of 23

pbejse
Mentor
Mentor

Curious, why not use _.QSELECT then?

 

- The purpose is to make a selection of several entities at once and delete them or use them for later use.--

 

We can add conditions for every object included in the selection, and the purpose here is to SAVE the selection set for later use? if you need to delete them might as swell use _.QSELECT right?

 

0 Likes