Discussion:
VBA, HandleToObject and handles of deleted entities.
(too old to reply)
ErPotenza
2007-02-13 08:36:44 UTC
Permalink
I'm doing some tests with VBA and I'm having a problem:

Public Sub Test()
Dim p1 As Point
Set p1 = Library.CreatePoint(0, 0, 0)
Dim p2 As Point
Set p2 = Library.CreatePoint(50, 50, 0)
Dim l As Line
Set l = ThisDocument.ModelSpace.AddLine(p1, p2)

Dim h As String
h = l.Handle

l.Delete

Dim o As Object
Set o = ThisDocument.HandleToObject(h)
End Sub

On the last line of the Sub,

Set o = ThisDocument.HandleToObject(h)

h is the handle of a deleted line, but HandleToObject returns the line
without a problem. In Autocad a similar situation would raise an
exeption. Is it possible to know when, given a handle, the respective
entity exists or not?

Thanks
Huib
2007-02-17 15:57:13 UTC
Permalink
Perhaps a bit crude, but what about trying the following code

Dim ItemExists as boolean
ItemExist = false

for each item in thisdocument.modelspace
if item.handle = h then
ItemExists = true
exit for
end if
next item

'now if there is a item with the handle ItemExist will be set to True....

Good luck.
Post by ErPotenza
Public Sub Test()
Dim p1 As Point
Set p1 = Library.CreatePoint(0, 0, 0)
Dim p2 As Point
Set p2 = Library.CreatePoint(50, 50, 0)
Dim l As Line
Set l = ThisDocument.ModelSpace.AddLine(p1, p2)
Dim h As String
h = l.Handle
l.Delete
Dim o As Object
Set o = ThisDocument.HandleToObject(h)
End Sub
On the last line of the Sub,
Set o = ThisDocument.HandleToObject(h)
h is the handle of a deleted line, but HandleToObject returns the line
without a problem. In Autocad a similar situation would raise an
exeption. Is it possible to know when, given a handle, the respective
entity exists or not?
Thanks
Loading...