PDA

View Full Version : Delete AutoCad Object using Visual Basic



supils
21st Feb 2005, 08:48 am
Using visual basic.. How can I delete an object given only its HANDLE OR OBJECT HANDLE.

Ex. I want to input an OBJECT HANDLE value in a textbox and then delete this object.

hendie
21st Feb 2005, 09:30 am
you wil need to convert the handle to the objects e-name and selct the object using the entity name

supils
21st Feb 2005, 09:33 am
I was a little bit confuse can you give me an example.. thanks

hendie
21st Feb 2005, 09:57 am
oops, I was mistaken, you don't need to convert the object....
this is vba but you should be able to convert it to VB (straight from the Autocad help)


For Each entry In ThisDrawing.ModelSpace
entHandle = entry.Handle
entry.Highlight (True)
MsgBox "The handle of this object is " & entHandle, vbInDim entHandle As String
Dim entry As AcadEntity
formation, "Handle Example"
entry.Highlight (False)
entry.Delete
ThisDrawing.Regen acActiveViewport

Next

supils
22nd Feb 2005, 01:29 am
Thank you responding on my question. The solution you have given actually work but solution you have given will actually search the item on the modelspace one by one and if the handle matches my given handle that will be the time to delete that object.. IS THERE ANY DIRECT WAY ON DELETING THE OBJECT ON THE MODELSPACE. BECAUSE IF YOU HAVE THOUSAND OF ENTRY IN THE MODELSPACE... IT WILL TAKE TIME TO DELETE A CERTAIN OBJECT. ANY OTHER SOLUTION..?

THANKS..

supils
22nd Feb 2005, 01:55 am
I ALREADY FOUND THE SOLUTION ... ANYWAY THANKS FOR THE REPLY..

THE SOLUTION IS THIS WHICH CAN BE FOUND IN THE HELP VB EXAMPLES..

' Find an object from a given handle
Dim tempObj As AcadObject
Set tempObj = ThisDrawing.HandleToObject(handle)

:D