See the top rated post in this thread. Click here

Results 1 to 5 of 5

Thread: Update a table data link in AutoCAD using VBA

  1. #1
    Member
    Join Date
    2017-01
    Posts
    8
    Login to Give a bone
    0

    Default Update a table data link in AutoCAD using VBA

    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

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Update a table data link in AutoCAD using VBA

    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.
    Code:
    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
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2017-01
    Posts
    8
    Login to Give a bone
    0

    Default Re: Update a table data link in AutoCAD using VBA

    Quote Originally Posted by Ed Jobe View Post
    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.
    Code:
    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

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    1

    Default Re: Update a table data link in AutoCAD using VBA

    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.
    Last edited by Ed Jobe; 2019-02-15 at 11:07 PM.
    C:> ED WORKING....

  5. #5
    Member
    Join Date
    2017-01
    Posts
    8
    Login to Give a bone
    0

    Default Re: Update a table data link in AutoCAD using VBA

    Quote Originally Posted by Ed Jobe View Post
    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

Similar Threads

  1. 2016: Link mtext to autocad table data
    By chris.chan.215092 in forum AutoCAD Tables
    Replies: 2
    Last Post: 2016-03-09, 02:14 PM
  2. 2014: Autocad table from Excel Data Link
    By sovby254640 in forum AutoCAD General
    Replies: 4
    Last Post: 2014-08-07, 11:19 PM
  3. update link excel & table in acad2009
    By zardeg in forum AutoCAD Tables
    Replies: 2
    Last Post: 2011-06-03, 02:43 PM
  4. Replies: 3
    Last Post: 2006-11-30, 05:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •