data link lisp

data link lisp

thomas_huntFMPXR
Contributor Contributor
169 Views
0 Replies
Message 1 of 1

data link lisp

thomas_huntFMPXR
Contributor
Contributor

anyone  have tips I keep getting the "Pick table: ; error: Automation Error. Problem in loading application" error from my code and unable. full code below:

 

(defun c:ss1 ( / ent tableObj filepath dlinkname dlm datalink)

  (vl-load-com)

  ;; Select the table
  (prompt "\nSelect a table to link to a new Excel file: ")
  (setq ent (car (entsel "\nPick table: ")))

  (if ent
    (progn
      (setq tableObj (vlax-ename->vla-object ent))

      ;; Check object type
      (if (/= (vla-get-objectname tableObj) "AcDbTable")
        (prompt "\n⚠ Selected object is not a table.")
        (progn
          ;; Let user select Excel file
          (setq filepath (getfiled "Select Excel File" "" "xlsx" 0))

          (if filepath
            (progn
              ;; Define unique data link name (timestamp based)
              (setq dlinkname (strcat "ExcelLink_" (rtos (getvar "cdate") 2 6)))

              ;; Get Data Link Manager
              (setq dlm (vla-GetInterfaceObject (vlax-get-acad-object) "AcDataLinkManager"))

              ;; Create new data link
              (setq datalink (vla-AddExcelDataLink dlm dlinkname filepath "" acDataLinkOptionFullPath))

              ;; Apply the data link to the table (attach to top-left cell)
              (vla-SetDataLink tableObj 0 0 datalink)

              ;; Update table with new data
              (vla-UpdateDataLink tableObj datalink acDataLinkUpdateOptionAll)

              (prompt (strcat "\n✔ Table updated with Excel file: " filepath))
            )
            (prompt "\n⚠ No Excel file selected.")
          )
        )
      )
    )
    (prompt "\n⚠ No table selected.")
  )

  (princ)
)
0 Likes
170 Views
0 Replies
Replies (0)