Lisp Function with Argument

Anonymous

Lisp Function with Argument

Anonymous
Not applicable

Hello,

I'm not a specialist in lisp, but I need to use it, so I took the lisp from Autodesk samples and changed it

When I use it without argument (filepath) and use file path hard coded inside the lisp -  it works good. But I need it with parameter, and don't know, how to make it. I get an error every time

This is my lisp:

 

(vl-load-com)
(defun c:Civil_Import(FilePath)

(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))

;; Define the import
(setq insertPoint (vlax-3d-point 0 0 0))
(setq importFile FilePath ;; Adjust path for your system
scalefactor 1)

;; Import the file
(vla-Import doc importFile insertPoint scalefactor)
;; (vla-ZoomAll acadObj)

(vla-Delete sset)
)

 

I try to call it from commandline  Civil_Import "C:\\ProgramData\\Temp\\test.Dxf"

and get error "Civil_Import ; error: too few arguments"

 

Help me, please, to fix the file.

 

0 Likes
Reply
Accepted solutions (1)
884 Views
4 Replies
Replies (4)

ВeekeeCZ
Consultant
Consultant

From command line you need to use all the name within parenthesis.

 

(c:Civil_Import "C:\\ProgramData\\Temp\\test.Dxf")

 

But it's unusual.

 

Usually, if we make a function with arguments, we don't use "c:"

Anonymous
Not applicable

Thank you

After researching of many samples, I understood how to use in arguments and it works!!!


(vl-load-com)
(defun c:Civil_Import(/ FilePath)
(setq filepath (getstring "\nEnter a dxf path: "))
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))

;; Define the import
(setq insertPoint (vlax-3d-point 0 0 0))
(setq importFile FilePath ;; Adjust path for your system
scalefactor 1)

;; Import the file
(vla-Import doc importFile insertPoint scalefactor)
;; (vla-ZoomAll acadObj)

(vla-Delete sset)
)

 

Just after the running (and loading of DXF) I see an error in commandline

; error: bad argument type: VLA-OBJECT nil

 

what does it mean? have I fix it? I don't see any problem.. I see that DXF was loaded

 Thank you

 

0 Likes

dbroad
Mentor
Mentor
Accepted solution

Take care when copying code.  Symbol names for example are just arbitrary names used to hold values.  The need to save your file information in a symbol named filepath and then to transfer that to importFile just because those are the argument names used in the examples is unnecessary.

 

Also, the need to delete sset is unnecessary because you never created it because you didn't export a drawing.  Remove the (vla-delete sset) from the program and all will be well.

Architect, Registered NC, VA, SC, & GA.

Anonymous
Not applicable

Thank you very much!! It helped!

0 Likes