Importing/Converting STEP files to DWGs using LISP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a few thousand ST(E)Ps that I need to turn into DWGs. I tried writing a script with LISP but I can't seem to get it to actually import anything. I've included the script I am trying to use and a comment on the line that is failing. I've only done very basic programming in LISP so I'm not the best at debugging it.
Is this the best solution for programmatically converting STPs to DWGs? (preferably through ACAD, open to other local conversion tools as well) Any pointers, resources, or help is greatly appreciated.
I originally had the import line as "-Import" But that would result in this error:
Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.
From my understanding the "-" means to call the function with params instead of popping up a dialog, but I don't think this issue is related to the Import command not working/me not understanding how to call it properly.
Here is the script I am trying to run:
(defun process-step-files (/ step-files output-dir)
(setq step-files (vl-directory-files "C:/Steps/" "*.step" 1))
(setq output-dir "C:/DWGs/")
(if (null step-files)
(prompt "\nNo .stp files found in the specified directory.")
(progn
(foreach step-file step-files
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq model-space (vla-get-ModelSpace doc))
(prompt "\nImporting...\n")
(prompt (strcat "C:/Steps/" step-file))
(command-s "IMPORT" (strcat "C:/Steps/" step-file)) ; FAILING ON THIS LINE/NOT MAKING IT PAST THIS LINE
(prompt "\nStep 1")
(setq imported-objects (vla-get-ImportedObjects doc))
(prompt "\nStep 2")
(setq imported-object (vla-item imported-objects 0))
(prompt "\nMoving imported object into model-space...")
(vla-move imported-object '(0 0 0) model-space)
(prompt "\nSaving...")
(command-s "-SAVEAS" (strcat output-dir (vl-filename-base step-file) ".dwg") "2018")
)
(princ "\nConversion process complete.")
)
)
)
(process-step-files)