DesignCAD 2D 2020 and DesignCAD 3D Max 2020 now available for sale! OR

Entity ID Macro
Read 905 times
May 15, 2019, 05:56:29 AM

Hi all,

Here is a macro that can find the entity id of stuff. You can either select an entity and it tell you the id, or type in a number and it selects the entity with that id.

It reports the id, type and layer, and whether the layer is on or not. If the layer is not on you will be asked if to turn it on.

If you type in a number it selects the entity and zooms in on it, and allows you to view-rotate around it, or do what I call an alternate-zoom (it zooms back a bit because in 3D dcad may zoom in closer that the size of the object, depending on the viewing angle.

Just highlight all the text in the box below and paste it in a new text file, then save it with the name I give at the very top, minus the apostrophe. If the macro doesn't work it'll be because this forum adds a lot of crazy texts to my posts. Let me know and I'll try to fix it. This forum also leaves out the spaces of anything pasted in, so it may be a little hard to read. I tried to put them back in but didn't do all.

Hope you find it useful,


Code: [Select]
'Entity ID & Layer Check.d3m
'by (Lar),
'6 oct 12
'original:Jan 19, 2006

'Macro can check any entity id number and layer, and zooms in (if layer is off it will not be seen, but the layer can be turned on)...


'sys(1027)=0  'message box style = OK (default)
'sys(1027)=1  'message box style = OK/Cancel
'sys(1027)=2  'message box style = Abort/Retry/Ignore
sys(1027)=3  'message box style = Yes/No/Cancel
'sys(1027)=4  'message box style = Yes/No
'sys(1027)=5  'message box style = Retry/Cancel

message "YES:  Click-Select an Entity... NO:  Find an Entity by ID number (max ",sys(9),")... CANCEL:  Abort...",CHR$(13),CHR$(13),"    (Note: in a Group, Solid or Grid only first entity will be reported)"
'1=OK, 2=Cancel, 3=Abort, 4=Retry, 5=Ignore, 6=Yes, 7=No
if sys(1028)=2 then end  'if cancel is clicked
if sys(1028)=6 then goto Sele  'if yes...
if sys(1028)=7 then goto Findd   'if no...

'sys(1027)=1    'ok/cancel message box
'message " Click  on an Entity to Select it (Note: in a Group or Solid only first entity will be reported) ...Or click Cancel to Abort..."
'if sys(1028)=2 then end  'if cancel is clicked...
GetSelect 1, e
entity e
GETATTR e, typee ,selectt, lay
sys(1027)=3    'yes/ no/ cancel message box
message "Entity No.",e, "of ",sys(9),". Type=",sys(90)," (",typee$,"), Layer ",lay," (",LayStat$,")...",CHR$(13),CHR$(13),"<<YES= Click- Select another entity... NO= Find an Entity by ID... CANCEL= Abort...>>"
if sys(1028)=6 then goto SeleAgain     'if yes is clicked
if sys(1028)=7 then goto Findd         'if no is clicked
if sys(1028)=2 then end                'if cancel is clicked

sys(80)=0   'deselect anything already selected...
'turn on point select mode to see entity when it becomes selected:
 'if point select mode is not on then turn it on and remember for de-activating...
if sys(345)=0 then     '[if point select mode is off]
PSM=0      'use this to turn it back on at end.
end if

inputtt$="Type the Entity Number you want to Locate (max ",sys(9),")..."
input [inputtt$] en
if en<1 or en>sys(9) then
sys(1027)=0    ' "ok" message box
message "Number was out of range. Type a number from 1 to ",sys(9),"..."
sys(1027)=3    'yes/ no/ cancel message box
goto Findd
end if
entity en
'getting layer and setting up for ;selectt'... note: if entity is not 'get-ted' first it's properties would all be 0 when 'put-ted'

GETATTR en, typeee, selecttt, lay, grouppp, reddd, greennn, blueee, soliddd



'select entity so it stands out...
PUTATTR en, typeee, selecttt, lay, grouppp, reddd, greennn, blueee, soliddd

'zoom in on selected entity...
minX=sys(196)-((sys(198)-sys(196))/5) 'Minimum X of selection bounding box, with 20% more
minY=sys(197)-((sys(199)-sys(197))/5) 'Minimum Y
minZ=sys(200)-((sys(201)-sys(200))/5) 'Minimum Z
maxX=sys(198)+((sys(198)-sys(196))/5) 'Maximum X
maxY=sys(199)+((sys(199)-sys(197))/5) 'Maximum Y
maxZ=sys(201)+((sys(201)-sys(200))/5) 'Maximum Z

if sys(344)=1 then goto Pas_SVP  'if 2d mode then skip Set Viewer Points...

<pointxyz [px,py,pz]
<pointxyz [minX, minY, minZ]
<pointxyz [maxX, maxY, maxZ]

'if layer is off then ask if to turn on...
if LayStat$="off" then
sys(1027)=4  'message box style = Yes/No
message "Entity's layer is off (layer ",lay,") - entity may be invisible,. Do you want it on?..."

'if no...
if sys(1028)=7 then goto OUT_

'if yes then turn on the entity's layer, go back up...
if sys(1028)=6 then

regen  '...regenerate so layer is seen...

end if
end if

if sys(344)=1 then goto OUT_  'if 2d mode then exit this portion...

'opt=0 'default option for input below...
'input "0=Rotate View <default>, 1=Alternate Zoom... or Cancel to End..." opt

sys(1027)=2  'message box style = Abort/Retry/Ignore

message "...First, some VIEWING OPTIONS...",chr$(13)," ROTATE VIEW click ABORT, for ALT-ZOOM click RETRY , to CONTINUE MACRO click IGNORE ..."

'1=OK, 2=Cancel, 3=Abort, 4=Retry, 5=Ignore, 6=Yes, 7=No
if sys(1028)=5 then goto OUT_

if sys(1028)=3 then gosub RotatView

if sys(1028)=4 then gosub AltZoom
goto Opts
<pointxyz [minX, maxY, maxZ]
<pointxyz [maxX, minY, minZ]
'1=OK, 2=Cancel, 3=Abort, 4=Retry, 5=Ignore, 6=Yes, 7=No
if sys(1028)=5 then goto OUT_
if sys(1028)=3 then gosub RotatView
if sys(1028)=4 then
end if
end if
'********  ********   **************  *************  ***********  ************  ********  ********
sys(1027)=3    'yes/ no/ cancel message box
message "Entity No.",en, "of ",sys(9),". Type=",sys(90)," (",typee$,"), Layer ",lay," (",LayStat$,")...",CHR$(13),CHR$(13), "<<YES= Find an Entity by ID... NO= Click- Select another entity... CANCEL= Abort...>>"
if sys(1028)=6 then goto Findd     'if yes is clicked
'if point select mode was activated then de-activate...
if PSM=0 then
end if
if sys(1028)=7 then goto Sele               'if no is clicked
if sys(1028)=2 then end                       'if cancel is clicked
'if ODD(lay)=0,     'no entities in layer x.
'if ODD(lay)=1,     'entities are in layer x.
if ODD(yal\2)=0 then
goto passs
end if
if ODD(yal\2)=1 and ODD(yal\4)=0 then
goto passs
end if
if ODD(yal\2)=1 and ODD(yal\4)=1 and ODD(yal\8)=1 then
goto passs
end if
LayStat$="on"   'if nothing else...
'0 Invisible and not editable
'2 Visible but not editable
'6 Visible and editable
'14 Set as current layer
if sys(90)=1 then typee$="Line"
if sys(90)=2 then typee$="Ellipse"
if sys(90)=3 then typee$="3D Text"
if sys(90)=4 then typee$="Curve"
if sys(90)=7 then typee$="Elliptical Arc"
if sys(90)=11 then typee$="Bezier Curve (4-point)"
if sys(90)=12 then typee$="Bezier Curve (Continuous)"
if sys(90)=13 then typee$="2D Text"
if sys(90)=15 then typee$="Attribute"
if sys(90)=16 then typee$="Circle, Circular Arc"
if sys(90)=17 then typee$="Hatch"
if sys(90)=22 then typee$="Text Arc"
if sys(90)=24 then typee$="Arrow"
if sys(90)=26 then typee$="Symbol"
if sys(90)=31 then typee$="Plane"
if sys(90)=32 then typee$="Grid Header"
if sys(90)=33 then typee$="Grid Line"
if sys(90)=68 then typee$="Construction Line"
if sys(90)=70 then typee$="Point Mark"
if sys(90)=71 then typee$="Attribute Definition"
if sys(90)=74 then typee$="Dimension, Angle"
if sys(90)=75 then typee$="Dimension"
if sys(90)=76 then typee$="Dimension, Diameter/Radius"
if sys(90)=77 then typee$="Dimension, Arc'
if sys(90)=78 then typee$="Dimension, Radius Progressive"
if sys(90)=79 then typee$="Dimension, Progressive"
if sys(90)=80 then typee$="Dimension, Chamfer"
if sys(90)=81 then typee$="Dimension, Coordinate"
if sys(90)=90 then typee$="Bitmap Image"
if sys(90)=92 then typee$="Double Line"
if sys(90)=93 then typee$="Double Curve"
if sys(90)=94 then typee$="Double Bezier"
if sys(90)=95 then typee$="Double Circle/Arc"
if sys(90)=96 then typee$="Double Elliptical Arc"
if sys(90)=97 then typee$="Double Ellipse"
if sys(90)=122 then typee$="Solid Surface"   'added 15nov17

« Last Edit: May 31, 2019, 07:47:39 AM by Lar »


May 15, 2019, 09:41:46 AM

That is really nice! I immediately added this to my custom toolbox! Seems to work OK.

What happens if a solid is broken across multiple layers? I don't have a fragmented solid to test it on right now (or at least one that I am aware of).

Sometimes "Solid Subtract" scatters a few facets of grids to Layer 0 (zero) and makes them material 0 (Aluminum) and color 0 (black = RGB 000).

« Last Edit: May 15, 2019, 09:55:26 AM by Dr PR »

DesignCAD user since 1987

May 15, 2019, 10:39:51 AM

I do see a peculiarity with the macro.

I have a solid that was created by extruding a "C" shaped plane. No matter where I click on the solid the macro reports the same entity number 95090 and type 31 (plane). I get the same result by clicking on either end of the solid or on the grid surface between the ends.

I tried selecting entity number 95091 and it was a plane that was part of another solid.

Likewise entity 95089 was a plane that is part of a third solid.

Next I tried selecting entity 95090 again and this time only one end plane of the solid was selected.

Then I selected the solid by clicking on the grid between the ends and the entire solid was selected and reported to be entity 95090 type 31 (plane).

So there is something peculiar about whether the whole solid is selected or just a part. I don't seem to be able to select the grid alone.


I selected the solid and copied/pasted it into an empty drawing.

Now when I select it with the macro it says it is entity 1 of 5 type 31 (plane).

If I use the macro to select entity 3 it does select the grid, reporting it to be type 33 (Grid Line).

Here are the results of selecting each entity by number:

1 = type 31 plane (one end of solid)
2 = type 32 grid header
3 = type 33 grid line (one end of grid)
4 = type 33 grid line (opposite end of grid)
5 = type 31 plane (opposite end of solid)

Selecting the grid header (entity 2) causes the entire solid to disappear from the window.


In this file containing only the solid I was able to select all five parts of the solid. But in the original drawing I could only find one plane by cycling through the entity numbers. I wonder if this means the parts of the solid did not have sequential numbers in the original drawing?


DesignCAD user since 1987

May 15, 2019, 11:58:39 AM

Phil, one of BasicCAD's limitations is you cannot delve into composite objects (Groups, Solids and Grid Surfaces) the way the SameAs finger can. With the SameAs finger you can click on a single object in a Group to get a particular property of that entity, but with basiccad when I click on a Group the whole Group gets selected. This macro only considers the first object in the Group (and it says so in the first message you get), since being able to tell where you clicked is a project for another day.

But come to think of it, I have another macro that can extract an object from a Group or Solid and for that to works the user has to click on one of the points of the object he wants extracted (a point whose coordinate is not shared by anything else in the group). The macro runs a check on all of the points in all of the entities and when a point coordinate matches the location of where the point was set then it stops there (uses the same 'first one down the list' technology). Maybe I could incorporate that thinking into this macro, when it encounters a Group or Solid. BUT... Some points it can't identify, like the center point of circles or the points in a Grid Surface (if you understand the inner workings of a grid surface you will appreciate why).

Now, I guess we have to understand how entity id's work to understand what this macro reports...

...Entity Id's are not fixed. An entity does not have a particular 'entity id' for its entire life, and if you copy and paste it somewhere it keeps the same id. No, the id is just the number of where an entity is located on a list of all the entities in a drawing, starting from the first entity you created down to the last
(imagine people standing on a bank line. When person #1 at the head of the line goes to a teller, then the person behind him who was person #2 becomes person #1)
. If you copy entity # 20067 from a file and paste it into an empty file then in the new file that paste becomes #1. If you then paste it again the second one becomes # 2. If you delete #1 then the second paste becomes #1. If you then undo the delete the un-deleted entity becomes #2 (can you imagine the confusion if both pasts had the same number?). So, unlike Group and Solid Id's the Entity Id list does not contain gaps. if you delete entity #1 then the id's of every other entity in the drawing drops down 1 digit.

I remember DT saying there is an internal unique id that lives with each entity but you need C++ or Visual Basic to access that. It's here somewhere on the forum how to access it, but its a long number. I imagine though, when pasting into a new drawing it takes on another number so there don't be conflicts when pasting in more of the same thing.

As for the grid disappearing, I have never encounter this and will look into it. If it looks like it will be a problem I will have to remove the macro from the forum.

« Last Edit: May 15, 2019, 12:08:06 PM by Lar »


May 15, 2019, 01:27:06 PM

When I say the grid disappears all I mean is that it is not displayed in the current window. It is still visible in the other windows (if any). After the macro is terminated it reappears in the current window.

It is a minor idiosyncrasy that really isn't worth bothering with. I just mentioned it for your information.

Another odd thing I noticed is that the points of the objects selected by the macro - when Point Select mode is enabled - do not always appear in all of the windows. This is a bit strange, but again nothing to bother about.

I do understand how the entity IDs are dynamic - just positions in the drawing list. I suppose that is why not all parts of a solid have sequential IDs - it depends upon the order in which they were created. So if a plane was created first, then some more entities were created, and the plane was then extruded to create a solid, the grid and opposite end plane may have ID numbers out of sequence with the first plane.

And what if the original solid is duplicated/mirrored/copied? The ID sequence could be different for each similar solid.


DesignCAD user since 1987

May 15, 2019, 08:03:54 PM
Ok, great on the Grids not actually disappearing from the file. I know sometimes when I do a slice operation the Grid Surfaces that are not in a Solid just completely disappears from the drawing.


May 31, 2019, 07:52:39 AM

Hi all,

If you copied and saved the macro above please re-copy and save. I just made an important fix.