1

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

  • I'm not familiar with the AutoCAD object model at all, but does the `DATALINKUPDATE` command take other (optional?) parameters? `ThisDrawing` sounds very much like it's the host document; hit F2 to bring up the *Object Browser*, and search for "SendCommand" - does the method only exist as a member of `ThisDrawing`? I mean it's possible there's a `TableLink.SendCommand` method; if that's the case then you might be able to dereference the specific table you want to update and run a more tightly-scoped command against it. – Mathieu Guindon Feb 14 '19 at 22:07
  • sendcommand isn't truly the problem, it simply mimics typing a command in the autocad command bar, DATALINKUPDATE can take several paths, the "U" makes it update an existing datalink then the "K" option updates all and the "D" option will update a specific one, that is where i run into a wall because i don't know whichone i have to update for each table i pick. – Carlos Raúl Gómez Feb 14 '19 at 22:17
  • I'll show myself out and leave this one to folks that know the AutoCAD object model then ;-) – Mathieu Guindon Feb 14 '19 at 22:21

1 Answers1

0

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

halfer
  • 19,824
  • 17
  • 99
  • 186