Repost: GetLinks problem in Event function

Discussion in 'AutoCAD' started by weslleywang, Sep 30, 2004.

  1. weslleywang

    weslleywang Guest

    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
     
    weslleywang, Sep 30, 2004
    #1
  2. weslleywang

    LochDhu Guest

    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
     
    LochDhu, Sep 30, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.