Has anyone gotten this error from this lisp code

Has anyone gotten this error from this lisp code

thomas_huntFMPXR
Contributor Contributor
207 Views
1 Reply
Message 1 of 2

Has anyone gotten this error from this lisp code

thomas_huntFMPXR
Contributor
Contributor

Command: (setq dataLinks (vla-GetDataLinkManager (vla-get-Database doc)))
"; error: bad argument type: VLA-OBJECT nil " and "error: no function definition: VLA-GETDATALINKMANAGER"

 

(defun c:SD_SolarEdgeTable ( / acadApp doc modelSpace dataLinks dataLinkName dataLinkId excelFile insertionPt tableObj )

  (vl-load-com)

  ;; Constants for Data Link options
  (setq acDataLinkRangeAll 1)
  (setq acDataLinkUpdateAll 3)

  ;; Setup
  (setq acadApp (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acadApp))
  (setq modelSpace (vla-get-ModelSpace doc))
  (setq dataLinks (vla-GetDataLinkManager (vla-get-Database doc)))

  ;; Ask user to select Excel file
  (setq excelFile (getfiled "Select Excel File" "" "xlsx" 0))

  ;; Exit if user cancels
  (if (not excelFile)
    (progn (princ "\nNo file selected. Exiting.") (exit))
  )

  ;; Unique Data Link Name
  (setq dataLinkName "SolarEdgeTable")

  ;; Try to get existing Data Link
  (setq dataLinkId (vl-catch-all-apply 'vla-GetDataLink (list dataLinks dataLinkName)))

  ;; If it doesn't exist, create one
  (if (vl-catch-all-error-p dataLinkId)
    (setq dataLinkId (vla-AddExcelDataLink dataLinks dataLinkName excelFile "" acDataLinkRangeAll))
  )

  ;; Ask for insertion point
  (setq insertionPt (getpoint "\nSpecify insertion point for the table: "))

  ;; Insert empty table; AutoCAD will resize it when updated
  (setq tableObj (vla-AddTable modelSpace (vlax-3d-point insertionPt) 1 1 5.0 20.0))

  ;; Attach Data Link to the table
  (vla-SetDataLink tableObj 0 0 dataLinkId)

  ;; Force table to update from Excel
  (vla-UpdateDataLink tableObj acDataLinkUpdateAll)

  (princ "\n Data-linked table inserted successfully.")
  (princ)
)
0 Likes
208 Views
1 Reply
Reply (1)
Message 2 of 2

cadffm
Consultant
Consultant

doublepost?

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/having-problem-identifying-the-funct...

 

Let us discuss it in your first thread, we don't need two of them.

Sebastian