Call Lisp function within itself

Call Lisp function within itself

MarkSanchezSPEC
Advocate Advocate
3,689 Views
27 Replies
Message 1 of 28

Call Lisp function within itself

MarkSanchezSPEC
Advocate
Advocate

I have a lisp routine that is loaded at startup via an MNL file like so;

 

(defun C:MyFunc ()

)

I would like to automatically run this routine once at startup. If I put a call to "(c:MyFunc)" BEFORE the defun, I get "error: no function definition C:MyFunc". This makes sense. However, when I call it AFTER the defun, the routine runs over and over in an endless loop. Is it possible to do this?

0 Likes
Accepted solutions (1)
3,690 Views
27 Replies
Replies (27)
Message 21 of 28

MarkSanchezSPEC
Advocate
Advocate

I have attached our MNL file. Everything between these tags is our code:

;; ============================================================
;; SPEC Services, Inc.
;; ============================================================

Normally it is named acetmain.mnl and replaces the OOTB copy at "...\AutoCAD 2016\Support\en-us"

You may see some stuff about Citrix but the behavior of non-stop looping also occurs within our corporate environment as well.

 

Thanks!

0 Likes
Message 22 of 28

JamesMaeding
Advisor
Advisor

oh, you are using it to affect the profile and all kinds of things where order matters.

Without question, you should not be doing this in a .mnl.

Simply put all this in an acaddoc.lsp, and put it in a top support folder, ideally the topmost.

Wrap it all in an s::startup function like:

(defun s::startup ()

do things....

)

that will run at the very end of startup and solve menu interactions. My acaddoc.lsp does all kinds of similar stuff.

That lisp is extensive enough that testing must happen in your environment.

I would guess though, that loading menus and switching profiles while acad is in the middle of menu loading causes the problems. I've never even tried that and its just bad technique IMO as it raises all kinds of difficult troubleshooting issues I don't need with 100 users.

Having said that, I often think a .mnl would be a great way to get around some cad manager that tries to lock everything down. Many forget about .mnls and you could slip your code in and take over like in Terminator.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 23 of 28

MarkSanchezSPEC
Advocate
Advocate

I just tried s::startup inside acadadoc.lsp, but that runs at AutoCAD startup (good) and each time a new drawing is open (bad). We want it to run it once per AutoCAD session, and available the first time a user initializes AutoCAD.

 

Thanks for the suggestion!

 

 

0 Likes
Message 24 of 28

MarkSanchezSPEC
Advocate
Advocate

@cadffm wrote:

Then add the (load "d:/mypath/myfile.lsp") statement to the custom ACAD.lsp file

and set ACADLSPASDOC to the only meanful value: 0

 


I've had success with putting the code in acad.lsp, with the ACADLSAPASDOC setting equal to 0 (which is the OOTB default and which it also enforces). This makes it instantly available, runs once per AutoCAD session (at startup), and does not get called each time a new drawing is open. Thanks for the suggestion.

0 Likes
Message 25 of 28

MarkSanchezSPEC
Advocate
Advocate

@SeeMSixty7 wrote:...  I fit is something you want run when they open AutoCAD place it in the ACAD.LSP file.

I've had success with putting the code in acad.lsp, with the ACADLSAPASDOC setting equal to 0 (which is the OOTB default and which it also enforces). This makes it instantly available, runs once per AutoCAD session (at startup), and does not get called each time a new drawing is open. Thanks for the suggestion.

0 Likes
Message 26 of 28

JamesMaeding
Advisor
Advisor
Accepted solution

@MarkSanchezSPEC 

to only run once per session, either put in acad.lsp, or do an if statement in the acaddoc.lsp like we do:

(defun S::STARTUP ()
(IF (NOT STARTUP-HAS-RUN) (PROGN (princ "\nRunning Initial Startup...") do stuff.... ) ) (SETQ STARTUP-HAS-RUN 1) (vl-propagate 'STARTUP-HAS-RUN)
;now add code you do want to run every session
)

This trick is cool because I don't like maintaining both acad.lsp and acaddoc.lsp.

This lets you put them in one.

That vl-propagate means "set this variable for this drawing and all future drawings opened, thus only letting that part run once.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 27 of 28

MarkSanchezSPEC
Advocate
Advocate

This is what we decided to go with: Acaddoc.lsp with S:STARTUP and the vl-propogate call. This allows us to have our setup instantly available, trusted, and automatically called only once per session.

 

Thanks for all your help: CADffm, SeeMSixty7, sea.haven, RONJONP, and Jmaeding for the solution!

0 Likes
Message 28 of 28

JamesMaeding
Advisor
Advisor

@MarkSanchezSPEC 

Very good, you are on your way to a better standard setup.

While we have your attention, another trick is this:

Export your profile, once all working and GUI elements how you want, to a ,arg file using options, Profiles tab.

Then, copy the acad icon and make the target like this, for 2019 as an example (use your .arg path of course)

"C:\Program Files\Autodesk\AutoCAD 2019\acad.exe" /p "C:\CAD_SUPPORT\A2019\+Standard Profiles\64 Bit\HA_ACAD2019.arg" /product "ACAD" /language "en-US" /nologo

 

for civil3d its:

"C:\Program Files\Autodesk\AutoCAD 2019\acad.exe" /ld "C:\Program Files\Autodesk\AutoCAD 2019\AecBase.dbx" /p "C:\CAD_Support\A2019\+Standard Profiles\64 Bit\HA_C3D2019.arg" /product "C3D" /language "en-US" /nologo

 

once you have that, you can set up a new machine by just copying your company tools and things to that machine, then run your icon and it sets up the profile first run. After that it simply switches to the profile, it does not recreate it or update it. We put a robocopy statement in our login script, so all I do to support the whole company is update the tools on our server and they get pushed to users on login. I guess that is another tip.

A really cool side effect is if a user messes up their profile, they can just rename it and close and open acad using the company icon. They get a reset profile. They still have the old one that someone can try to fix later.

 

For some real fun, our startup even has statements to control the support paths and other things that user tend to mess with. So it heals itself for many things. Good luck.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties