Repost: GetLinks problem in Event function

Repost: GetLinks problem in Event function

wesbird
Collaborator Collaborator
259 Views
1 Reply
Message 1 of 2

Repost: GetLinks problem in Event function

wesbird
Collaborator
Collaborator
Hi:
I have a function to check if any one change(delete, modify) the pline with link value, I will create a flag in the drawing (dictionary).
Now I have a "Run-time error '-2147467259(80004005) Unspecified error" error at
Set Links = DbConnect.GetLinks(, objIds, CAO.kEntityLinkType)

Does this mean GetLinks does not work with the object within a ObjectModified Event? How should I make this work?

Thank you a lot and I really appreaciate your help.


Wes



Here is my code:

Private Sub AcadDocument_ObjectErased(ByVal ObjectID As Long)

AutoCADDatabaseChangedEvent ObjectID
End Sub

Public Function AutoCADDatabaseChangedEvent(ByVal ObjectID As Long)

If IsRealSuiteRunning Then GoTo Final

' check if link object
Dim colTmp As Collection
Set colTmp = GetKeyValue3(ObjectID)

If colTmp.Count > 0 Then
If ReadProfile2(dictProfileName, dictDBKey) = 1 Then
IsRealSuiteRunning = True
WriteProfile2 dictProfileName, dictDBKey, 2
End If
End If

Final:
End Function

Function GetKeyValue3(ByVal ObjID As Long) As Collection
Dim Ret As New Collection

' Init dbConnect
Set DbConnect = GetInterfaceObject("CAO.DbConnect.16")

Dim objIds(0 To 0) As Long
objIds(0) = ObjID

Dim Links As CAO.Links
Set Links = DbConnect.GetLinks(, objIds, CAO.kEntityLinkType)
' Debug
If DDebug < 5 Then MsgBox "Links.Count: " & Links.Count & vbCrLf & _
ObjID & "-" & Links.Item(0).ObjectID, , "Debug"

If Links Is Nothing Then GoTo Final

Dim link As CAO.link
Dim Kvs As CAO.KeyValues
Dim kv As CAO.KeyValue
Dim kvEL As kvCol
For Each link In Links
Set Kvs = link.KeyValues

' iterate each KeyValue
' debug
If DDebug < 20 Then
For Each kv In Kvs
MsgBox "Name:" & kv.FieldName & " Value:" & kv.Value, , "Debug"
Next kv
End If

Set kvEL = New kvCol
kvEL.KeyValue = Kvs(0).Value
Ret.Add kvEL
Next link

Final:
Set Links = Nothing
Set GetKeyValue3 = Ret
End Function
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
0 Likes
260 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Your code looks fine, the problem may be that you are trying to reference an object that has been deleted. Try calling your function and passing a known ObjectID for an object that still existing in the DWG and see if you get the error.

Scott
0 Likes