Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp Function with Argument

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
830 Views, 4 Replies

Lisp Function with Argument

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.

 

4 REPLIES 4
Message 2 of 5
ВeekeeCZ
in reply to: Anonymous

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:"

Message 3 of 5
Anonymous
in reply to: ВeekeeCZ

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

 

Message 4 of 5
dbroad
in reply to: Anonymous

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.
Message 5 of 5
Anonymous
in reply to: dbroad

Thank you very much!! It helped!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report