.src to .lsp issue porting over how to get more info

.src to .lsp issue porting over how to get more info

QNashJSRL8
Contributor Contributor
703 Views
11 Replies
Message 1 of 12

.src to .lsp issue porting over how to get more info

QNashJSRL8
Contributor
Contributor

src is as follows

filedia 0
new "{pathtofile}\2021-target-Imperial-unitless-scales.dwt"
pasteorig
zoom e
filedia 1
-layer ps Black *

lsp is 

(defun c:TranslateFilesBHI ()
  (setvar "filedia" 0)
  (command "._new" "{pathtofile}\2023-target-Imperial-unitless-scales.dwt")
  (command "._pasteorig")
  (command "._zoom" "e")
  (setvar "filedia" 1)
  (command "._-layer" "ps" "Black" "*")
  (princ)
)

the out put also gives
Command: (c:TranslateFileBHI)
Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.


So how do i even know what it is crashing on in the output window

QNashJSRL8_0-1727373483982.png

 



0 Likes
704 Views
11 Replies
Replies (11)
Message 2 of 12

paullimapa
Mentor
Mentor

Troubleshoot by copy and pasting each Autolisp line of code in the command line and see if it crashes starting with

(setvar "filedia" 0)

Also after a crash like this you need to manually set filedia back to 1 at the command line


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 12

ec-cad
Collaborator
Collaborator

Possible that {pathtofile} is 'nil' since you are not 'passing' that value into the Lisp function.

Paste the line: (command "._new" "{pathtofile}\2023-target-Imperial-unitless-scales.dwt")

into the Command Prompt line, to see if it's nil. Also, if it contains a "\\" on the right end of

{pathtofile} variable, you will need to remove the \ before 2023.

Other than that, code looks ok. It's .scr, not src.

 

ECCAD

Message 4 of 12

Kent1Cooper
Consultant
Consultant

That error message about (command) vs. (command-s) suggests to me that you have some other routine that has replaced the native *error* handler with something that includes a (command) function [such as to do Undo End?], and that has not properly restored AutoCAD's native *error* routine when it's done.  But that only kicks in after an error has triggered the *error* handler, so that still needs to be identified.

 

But in any case, AutoLisp can't start in one drawing and continue in another, unless perhaps you are in single-drawing interface.  Could that have something to do with the crashing?

 

Also, for me [Acad2020 here], "ps" is not a valid option in a -Layer command -- are you in a different-language version, or is that an option in newer versions than mine?  [I can check in 2025 later elsewhere.]

 

And your path-to-file [whatever it really is] can have regular backslashes as separators in a Script, but in AutoLisp they must be either forward slashes or double backslashes, because a single backslash is a special-character trigger.

Kent Cooper, AIA
0 Likes
Message 5 of 12

paullimapa
Mentor
Mentor

actually -Layer _PS does exist if currently in Name PlotStyle dwg:

paullimapa_0-1727376286842.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

actually -Layer _PS does exist ....


[Okay, that's a newer-version-than-2020 option.]

Kent Cooper, AIA
0 Likes
Message 7 of 12

paullimapa
Mentor
Mentor

@QNashJSRL8 

Read up on how lisp needs to handle characters like the "\" needs to be entered as "\\":

https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-C8E55E82-0104-4305-95E5-1671628A2FF3


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 12

paullimapa
Mentor
Mentor

nope, I copied and pasted that command line from AutoCAD 2020


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 12

ec-cad
Collaborator
Collaborator

Paulli,

No, I was just saying that if that varible {pathtofile} , already has "\\" on the end,

Op would have to remove the (3 rd) \ just before the 2023.

Like in when you do (getvar "dwgprefix"). it returns "\\" on the end.

 

ECCAD

0 Likes
Message 10 of 12

paullimapa
Mentor
Mentor

agreed


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant

I don't have it, but maybe I don't understand what you meant by "if currently in Name PlotStyle dwg."

Kent1Cooper_0-1727377682572.png

[In any case, it's probably not relevant to the OP's issue.]

Kent Cooper, AIA
0 Likes
Message 12 of 12

paullimapa
Mentor
Mentor

Your drawing is probably in Color Dependent Plot Style.

You can either use CONVERTPSTYLES command to change the dwg to Named Plot Style

paullimapa_1-1727378325423.png

 

Or start a New dwg and select the acad-Named Plot Styles.dwt template

paullimapa_1-1727378060625.png

Then enter -LAYER command & now you should see PStyle as one of the options

paullimapa_2-1727378138998.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos