Select object from objectidcollection

Select object from objectidcollection

Anonymous
Not applicable
641 Views
1 Reply
Message 1 of 2

Select object from objectidcollection

Anonymous
Not applicable

Hi. I have two selection set. I remove one selectionset from another by using ObjectIdCollection but I don't know how I can for example remove selected object in ObjectIdCollection. I try something like this:

For Each selected As SelectedObject In acObjIdColl If Not IsDBNull(selected) Then 
Dim ObjErase As Entity = acTrans.GetObject(selected.ObjectId, OpenMode.ForWrite) 
If Not IsDBNull(ObjErase) Then 
ObjErase.Erase() 
End If 
End If 
Next

But it isn't work.

0 Likes
642 Views
1 Reply
Reply (1)
Message 2 of 2

ambrosl
Autodesk
Autodesk

Are you trying to remove the object from the selection set or from the database?

 

If you are trying to remove the object from the selection set, but not the drawing you will want to use the Remove or RemoveAt methods of the ObjectIdCollection. You can learn more about selecting sets and removing objects from there here: https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-C1573808-66CF-4E40-8E7A-C52DFBCA352E

 

If you are trying to remove an object from the database, you need to use the Erase method as you have in your code but you must also make sure you do a Commit with the Transaction Manager after your For loop.  The changes won't take place unless a commit occurs, and if you don't before the Transaction Manager goes out of scope all changes made will be rolled back as an abort occurs (Commit and Rollback Changes).  You can learn more about how to erase an object here: https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-A9283274-3E5B-4739-975B-03A30536EE64



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes