PDA

View Full Version : Update a table data link in AutoCAD using VBA



carlosrgns
2019-02-14, 10:35 PM
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

Ed Jobe
2019-02-15, 04:28 PM
Since you are using SendCommand, you can only process lisp at the command line. I wrote the following function to use by passing a vba entity to lisp. At the point in the prompt where it asks for an selection, you need to use the (handent) function to get a lisp ename. In vba, use a selection method to obtain a SelectionSet of the desired table. Iterate the ss to get the table object and pass it to the following function.


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

carlosrgns
2019-02-15, 10:30 PM
Since you are using SendCommand, you can only process lisp at the command line. I wrote the following function to use by passing a vba entity to lisp. At the point in the prompt where it asks for an selection, you need to use the (handent) function to get a lisp ename. In vba, use a selection method to obtain a SelectionSet of the desired table. Iterate the ss to get the table object and pass it to the following function.


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


Ok got the function, selecting the table was already done, now the output of the function is "(handent "202AD81")"
Now my ignorance kicks in again, how do I turn the handler into the datalink name needed for the "datalinkupdate" function?

also, I'm not maried to datalinkupdate, I'm open to any other method that would update only the datalink attached to the selected table however my knowledge of lisp and .net is limited at best

Ed Jobe
2019-02-15, 10:58 PM
The datalinkupdate command can also ask you to select a table object. Use that option.

DATLINKUPDATE
VbCR 'for the prompt to update
prompt to select> pass in the handle

ThisDrawing.SendCommand "DATALINKUPDATE " & VbCr & "(handent "202AD81")" & VbCr

ThisDrawing.SendCommand "DATALINKUPDATE " & VbCr & Ent2lspEnt(objTable) & VbCr

The above in untested for the syntax, you might need to add a space or two.

carlosrgns
2019-02-16, 01:24 AM
The datalinkupdate command can also ask you to select a table object. Use that option.

DATLINKUPDATE
VbCR 'for the prompt to update
prompt to select> pass in the handle

ThisDrawing.SendCommand "DATALINKUPDATE " & VbCr & "(handent "202AD81")" & VbCr

ThisDrawing.SendCommand "DATALINKUPDATE " & VbCr & Ent2lspEnt(objTable) & VbCr

The above in untested for the syntax, you might need to add a space or two.



Sir you have been most helpfull, the exact syntax is as follows:

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