Autolisp: how embed or to load a lisp routine in a drawing

Autolisp: how embed or to load a lisp routine in a drawing

Anonymous
Not applicable
3,250 Views
14 Replies
Message 1 of 15

Autolisp: how embed or to load a lisp routine in a drawing

Anonymous
Not applicable

Good afternoon,

 

can i load a lisp code automatically when a certain drawing is opened? Not sure if lisp can be embedded in a specific drawing or if i have to load it at Autocad startup for all of my drawings.

 

Thanks!

0 Likes
3,251 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

Just to make sure i explained right, i have a lisp code that i only want to load when a specific drawing is opened. At the moment i have it in the startup suite so it's loaded when Autocad starts so it is available for all my drawings.

0 Likes
Message 3 of 15

AllenJessup
Mentor
Mentor

The only way I can think of doing it for an individual drawing would be to write a batch file that opens that particular drawing and then loads the lisp file. Possibly through a script.

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 4 of 15

AllenJessup
Mentor
Mentor

OK. Another possibility is through the use of ICON SWITCHES. You could create an Icon that opens a particular drawing and calls a script to load the lisp.

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 5 of 15

Anonymous
Not applicable

Thanks for your replies Allen.

 

Ii was hoping i could "embed" the lisp routing in the file because i have to place it on our shared drive and needed anyone that open my drawing to have the routine available instead of having to make it available and having to ask everyone to load the lisp code when the use the drawing.

0 Likes
Message 6 of 15

AllenJessup
Mentor
Mentor

I don't think that's possible. You might be able to use an Embedded Macro to load the lisp. So only the drawing with that macro embeded would load the lisp. The lisp would have to be in a pathw available to everyone.

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 7 of 15

krzysztof.psujek
Advocate
Advocate
Actually you can try this
http://www.cadstudio.cz/en/apps/autoexec/
but I never tested it. If it won't work follow with @AllenJessup suggestions.

Chris
Message 8 of 15

AllenJessup
Mentor
Mentor

Nice. I thought there might be something out there but didn't find it when I searched. Hopefully it will work for the OP.

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 9 of 15

krzysztof.psujek
Advocate
Advocate
I knew I saw it once and even I downloaded it (it is in my lisps pack) but I treated it rather as a curiosity.

Chris
0 Likes
Message 10 of 15

dgorsman
Consultant
Consultant

Backing things up a bit from the other responses...

 

Why are you using something that no-one else is, on a single drawing?  Why are they not using those tools as well?  Should you be doing this, even if you consider it "faster" "better" etc.?

 

Any user worth their salt, when confronted by a "This drawing has embedded macro, do you want to run?" warning, will answer not just "No" but "Hells NO!" in this day and age.

 

If users are supposed to be doing things a certain way, then it should be loaded by default for all users - everyone, doing the same thing, the same way, each time, every time.  That can be done with a bit of organization e.g. LISP and other common files in read-only network locations, loaded through ACAD.LSP and ACADDOC.LSP or other methods.  That's available without any embedding or custom libraries/third-party tools.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 11 of 15

Joe-Bouza
Mentor
Mentor
You can add any lisp to the suitcase in your template and they always be available

Joe Bouza
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 12 of 15

chriscowgill7373
Mentor
Mentor

I'd have to agree with some of the responses the other users have posted,  embedding a lisp file is akin to a virus, which is bad.

Have you tried revising the lisp so it checks the current drawing name before it runs?  if you only want it running on a single drawing, it should be easy enough to add a check for the drawing name.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2026 on Windows 11

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 13 of 15

Anonymous
Not applicable

I created this lisp code making available a new command (or routine) that is only useful using a specific drawing.

To me it doesn't make sense to load some code if you will never use it that's is why i only wanted it to load with my drawing otherwise it would be useless.

0 Likes
Message 14 of 15

Anonymous
Not applicable

Specifically i made a solid and the lisp function tells the user the height of the solid in the coordinates given by the user on the XY.

0 Likes
Message 15 of 15

TerryDotson
Mentor
Mentor

While I agree with some here on embedding code that could execute on others machines, there is absolutely nothing wrong with loading a specific lisp file when a drawing is opened.  It can set variables back to needed values, provide drawing specific tools, and much more.  There are tens of thousands of CAD users who can do it with a simple click of a toggle in ToolPac.

 

To the OP, consider creating a custom partial menu and have it load.  The key is to have a companion MNL file of the same name as the CUIx.  When each drawing loads, AutoCAD will load the MNL file.  In that MNL file you can put a piece of lisp code to get the current drawing path/name, change .dwg to .lsp and if (findfile) finds it, load it.  In other words the MNL file could be your drawing.lsp loader (hopefully you won't need to use s::startup).