Update a table data link in AutoCAD using VBA

1.2k Views Asked by At

I have an issue, have an AutoCAD file with a ton of data links and would like to update only the data links related to a speciffic table. Simmilar to the functionality of selecting a table with data links, right clicking and selecting Update Table Data Links.

i have the following code:

Private Sub Update_table_data_link(tblRef As AcadTable)

ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "K" & vbCr

End Sub

It works but updates all the data links in the drawing (which is a problem) so a perfect solution would either let me get what links are associated to tblRef
and change the line to:
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "D" & vbCr & "datalink_name_from_tblRef" & vbCr

or directly send the command to update the links to tblRef

1

There are 1 best solutions below

0
Carlos Raúl Gómez On

After much digging around and a lot of help, here is the answer:

Private Sub Update_table_data_link(tblRef As AcadTable)

    ThisDrawing.SendCommand "DATALINKUPDATE " & vbCr & "U" & vbCr & Ent2lspEnt(tblRef) & vbCr & vbCr

End Sub

Public Function Ent2lspEnt(entObj As AcadEntity) As String
    'Designed to work with SendCommand, which can't pass objects.
    'This gets an objects handle and converts it to a string
    'of lisp commands that returns an entity name when run in SendCommand.
    Dim entHandle As String

    entHandle = entObj.Handle
    Ent2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
End Function

note that "Update_table_data_link" has a table as input