Autoload

Autoload

andreas7ZYXQ
Advocate Advocate
1,480 Views
8 Replies
Message 1 of 9

Autoload

andreas7ZYXQ
Advocate
Advocate

Currently im using the startup function.

All my lisp files are placed in a directory "Autoload"

 

Inside acaddoc.lsp i have a line for every command.

(autoload "LineProgram" '("DrawLine"))

is there any way to customize this so i dont have to change my acaddoc.lsp and add a new command every time i have a new .lsp file in my autoload directory?

Must be some way to achieve this. Ive been searching but i cant find anything good that cover this.

Any ideas?

0 Likes
Accepted solutions (1)
1,481 Views
8 Replies
Replies (8)
Message 2 of 9

pbejse
Mentor
Mentor

@andreas7ZYXQ wrote:

 

is there any way to customize this so i dont have to change my acaddoc.lsp and add a new command every time i have a new .lsp file in my autoload directory?

Must be some way to achieve this. Ive been searching but i cant find anything good that cover this.

Any ideas?


Yes, call another routine outside of acaddoc.lsp then you can make changes off that file without adding any lines on your acaddoc.lsp

 

Refer to this thread  ---> AutoLISP Startup Routine Debugging Help Request

 

 

0 Likes
Message 3 of 9

Ranjit_Singh
Advisor
Advisor

If you combine them all in one file then you could do this

(autoload "combinedprogram" '("drawline" "drawcircle" "dowhatever"))

Simply ad to the functions list when you create new ones. However, when any of those commands is called the entire program will be loaded. If, for whatever reason, you intend to keep all those functions in separate files then you do need a separate autoload for each. You can reduce the amount of typing by combining everything in a mapcar. That way whenever you have a new program, add the program name and function name to the mapcar lists. You can see that in this case only one program is loaded when I call a function, identical to what you are doing now with multiple statements

 

(mapcar '(lambda (x y) (eval (list 'autoload x y))) '("lineprogram" "circleprogram" "whateverprogram") '('("drawline") '("drawcircle") '("dowhatever")))

combine_autoloads.gif

 Although given the amount of RAM we have these days, it should not be a problem to use a combined program with all the functions

0 Likes
Message 4 of 9

phanaem
Collaborator
Collaborator
Hi
I don't think you should change something. You are doing this just once for each file.
But if you insist, you can put all your lisp files in a specific folder, then, inside your acaddoc file, use vl-directory-files to get a list of all the files and load them. For autoload, you should have a very strict rule about file name and command name, in order to feed autoload function correctly.
Message 5 of 9

pbejse
Mentor
Mentor

OR just create an installer package 

 

I would suggest you begin to dig into Autlooader. .. for light reading  ---> Autodesk Autoloader White Paper 

 

oh my, So many choices, so Little time.. 🙂

0 Likes
Message 6 of 9

Ranjit_Singh
Advisor
Advisor
Accepted solution

@phanaem wrote:
Hi
I don't think you should change something. You are doing this just once for each file.
But if you insist, you can put all your lisp files in a specific folder, then, inside your acaddoc file, use vl-directory-files to get a list of all the files and load them. For autoload, you should have a very strict rule about file name and command name, in order to feed autoload function correctly.

@phanaem that's a very good suggestion. I would definitely go this route. And if @andreas7ZYXQ makes a habit to name his files and functions always the same, he can feed into the mapcar automatically all filenames and never have to visit the autoload portion again. I created a directory and added it to the support and trusted locations path. My acaddoc now contains below code and as you can see it has no explicit filenames or function names. They are grabbed from the "My lisps" directory.

(mapcar '(lambda (x y) (eval (list 'autoload x y)))
(mapcar 'vl-filename-base (vl-directory-files "C:\\Users\\ranjits\\AppData\\Roaming\\Autodesk\\AutoCAD 2015\\R20.0\\enu\\Support\\My Lisps" "*.*" 1))
(mapcar 'read (mapcar '(lambda (x) (strcat "\'(\"" x "\")")) (mapcar 'vl-filename-base (vl-directory-files "C:\\Users\\ranjits\\AppData\\Roaming\\Autodesk\\AutoCAD 2015\\R20.0\\enu\\Support\\My Lisps" "*.*" 1)))))

Anytime you create a new function just drop into the right directory and it should be available whenever AutoCAD starts. Be sure to name the files and functions exactly the same.combine_autoloads_2.gif

 

Message 7 of 9

pbejse
Mentor
Mentor

@phanaem wrote:
... But if you insist, you can put all your lisp files in a specific folder, then, inside your acaddoc file, use vl-directory-files to get a list of all the files and load them....

Even better Smiley Happy

 

 

0 Likes
Message 8 of 9

scot-65
Advisor
Advisor
With a little work, adding a line to the LSP file
can easily be converted into a "cheat sheet"
in case one forgets what is available (or newbies
not knowing what is available).

Most of my stand-alone LSP files have been
compiled into FAS. Because of this, a more
detailed description of the file name is required.
The detailed description does not always match
the command name.

Inside my MNL file I make a call to load the file
"MyMasterUtilities.lsp". Inside this file is all
the loading and command names. Nothing else.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 9 of 9

andreas7ZYXQ
Advocate
Advocate

@Ranjit_Singh This is exactly what im looking for. Not 100% sure about the code but it works flawless.... 

 

Thanks alot for the help.

0 Likes