Problem loading lisp using a script when using reference instead of full path

Problem loading lisp using a script when using reference instead of full path

l.pachecoXMU86
Participant Participant
613 Views
5 Replies
Message 1 of 6

Problem loading lisp using a script when using reference instead of full path

l.pachecoXMU86
Participant
Participant

Hi everyone, I have a  peculiar problem which I've been scratching my head over for too long now...

 

I am writing an .scr script which I would like to use to open a dwg, load an autolisp routine and the run a command from that routine before saving and closing the drawing:

 

_.open "PATHTODRAWING" (load LISPFILE) (c:LISPCOMMAND) _.qsave _.close

 

I have verified that the drawing opens, and I have verified that the commands work correctly when the lisp routine is loaded correctly, however I am having problems loading the lisp routine.

 

Here's where it gets interesting. If I put the full path to the lisp in the load function, it works fine:

 

_.open "PATHTODRAWING" (load "\\\\tsclient\\I\\Drawings - Documents\\2 - Clients\\CONFIDENTIAL\\CONFIDENTIAL\\1 Motor Schematic Diagrams 100\\3 Reference\\Templates\\TestGeneration\\00_Complete\\Update\\Autogen_LISP\\Autogen_LISP\\Scripts\\Autogen.lsp") (c:Autogen root_directory data_file) _.qsave _.close

 

However, based on how this software is going to be used, we don't want the full path to the lisp routine and instead want to use the relative path.

 

I can get the path in two different ways (I haven't written the full code for how here) and both of them give me the correct path, which is the exact same path which works if pasted directly into the load function. I've even verified this by copying the path they output, and setting it as the full path in the script, which ends up working.

 

Method 1:

 

Command: (LM:findfile "Autogen.lsp" scripts_path)

 

Returns
"\\\\tsclient\\I\\Drawings - Documents\\2 - Clients\\CONFIDENTIAL\\CONFIDENTIAL\\1 Motor Schematic Diagrams 100\\3 Reference\\Templates\\TestGeneration\\00_Complete\\Update\\Autogen_LISP\\Autogen_LISP\\Scripts\\Autogen.lsp"

 

Method 2:

 

Command: (setq autogen_path (strcat scripts_path "Autogen.lsp"))

 

Returns:
"\\\\tsclient\\I\\Drawings - Documents\\2 - Clients\\CONFIDENTIAL\\CONFIDENTIAL\\1 Motor Schematic Diagrams 100\\3 Reference\\Templates\\TestGeneration\\00_Complete\\Update\\Autogen_LISP\\Autogen_LISP\\Scripts\\Autogen.lsp"


But, when I replace the full path with either of these two commands, the routine doesn't load and nothing happens. 

 

_.open "PATHTODRAWING" (load (LM:findfile "Autogen.lsp" scripts_path)) (c:Autogen root_directory data_file) _.qsave _.close

 

_.open "PATHTODRAWING" (load autogen_path) (c:Autogen root_directory data_file) _.qsave _.close

 

I have also tested the syntax for (load (LM:findfile "Autogen.lsp" scripts_path)) in another lisp routine and it worked just fine, so I'm at a loss as to what is going on here.

 

Any advice would be appreciated!

0 Likes
Accepted solutions (1)
614 Views
5 Replies
Replies (5)
Message 2 of 6

Scottu2
Advocate
Advocate

In the script file try placing each command on a different line.
Try just _OPEN instead of _.OPEN
Use the ! before the variable name, if !PATHTODRAWING is a predefined variable
Also, after the AutoGen.lsp is loaded, the commands are entered as they are typed manually.

_open !PATHTODRAWING
(load (LM:findfile "Autogen.lsp" scripts_path))
Autogen

!root_directory data_file

if Autogen is a changed to a subroutine instead of a C: command

(Autogen root_directory data_file)
_.qsave
_.close

Message 3 of 6

l.pachecoXMU86
Participant
Participant

Thanks for the response. Placing each command on a different line gave me some clarity which led to finding out what was happening.

0 Likes
Message 4 of 6

l.pachecoXMU86
Participant
Participant
Accepted solution

I found out what the issue was. Basically, I was calculating the path variables in the script prior to opening the drawings. When I did this, the autogen path was set, but would then reset itself once I opened the next drawing using the _.open command. The autogen_path variable would now be nil, and not do anything once called by the load function. To fix this, I set the autogen path AFTER opening the drawings, like so:

 

_.open "PATHTODRAWING"
(setq autogen_path (strcat (getvar 'dwgprefix) "..\\Scripts\\Autogen.lsp"))
(load autogen_path)
(c:Autogen root_directory data_file)
_.qsave
_.close

 

Which worked. I am still trying to figure out how to loop this script so I don't have to copy and paste it 50 times, however this specific issue has been solved.

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

Do you mean 50 Pathtodwg names ? Just use lisp to write the script.

 

0 Likes
Message 6 of 6

l.pachecoXMU86
Participant
Participant

Thanks for the response. Hmm, how would I run the lisp to generate that script independent of AutoCAD though?

 

I'm trying to get the whole process down to a single button press. Right now, I'm using python to generate the script file, and plan on using a batch file to initiate the whole process - like so:

 

1. Double click batch file - which completes the following operations:

2. Initiate .exe (written in python) which generates the script file from all 50 paths

3. Open AutoCAD, and run the generated script file.

 

Not sure how the lisp would fit into this equation (I believe in this context you suggest using it in it would be replacing the python program, if I was to use it). Would you have to save the lisp as an exe to be able to run it from the batch file?

0 Likes