Hi, I'm just looking for some general advice. We have a few lisps that we have scattered about that we would like to consolidate. I would like to be able to reduce our customs lisps to one or two. We would like to leave the default acad.lsp, acaddoc.lsp, acad2014.lsp, etc. alone, but autoload load our company custom stuff. We have some routines that need to load with each drawing and some that only need to load per session.
What are some easy ways organize lisp routines so they are easy to manage and load properly? Is there a way to do with without altering the out of the box lisps?
Solved! Go to Solution.
Solved by martti.halminen. Go to Solution.
The simplest way to achieve what you are looking for is:
1) Adding lines in acaddoc.lsp
(load "MyRoutine_00.lsp")
(load "MyRoutine_01.lsp")
(load "MyRoutine_02.lsp")
(load "MyRoutine_03.lsp")
; etc
2) Accoding to your statement - "...some that only need to load per session":
Create a lsp file "MyRoutine_00" with an "IF" statement. for example:
(defun c:MyRoutine_00 ()
(if (eq "dwgname" "XXXXX.dwg)
(progn (load "MyRoutine_04.lsp")
(load "MyRoutine_05.lsp")
; etc
); end of progn
); end of if
);end of MyRoutine_00
Everytime you want to load the function(s), you enter "MyRoutine_00" in the command line.
Of course, you may need to make some changes on "trustedpaths". Please see the HELP documents.
- This is only an idea and you need to change the details to suit.
HTH
@Jroper wrote:Hi, I'm just looking for some general advice. We have a few lisps that we have scattered about that we would like to consolidate. I would like to be able to reduce our customs lisps to one or two. We would like to leave the default acad.lsp, acaddoc.lsp, acad2014.lsp, etc. alone, but autoload load our company custom stuff. We have some routines that need to load with each drawing and some that only need to load per session.
What are some easy ways organize lisp routines so they are easy to manage and load properly? Is there a way to do with without altering the out of the box lisps?
On vanilla AutoCAD acad.lsp and acaddoc.lsp don't exist out of the box, and they are specifically intended for the user's customizations so you are free to create those. Don't touch acad2014.lsp and acaddoc2014.lsp, those are the ones intended for Autodesk use.
acad.lsp for the once-only stuff, acaddoc.lsp for every drawing.
On AutoCAD Mechanical there is some Autodesk stuff also in acaddoc.lsp, but you can just add your own parts in front of that.
If you have several files of your customizations, it is useful to compile them all into one .vlx file for faster loading.
- we are loading about 1700 defuns in acaddoc.lsp, takes less than two seconds.
--
Providing of course you keep a copy of the source code - VLX cannot be edited. So its a good idea to get everything squared away (and properly archived!) before you start compiling.
I have read all of the responses.
I have created a slew of macros and I have all of them load when AutoCAD starts everytime. If you don't want a command to be in a drawing, why not load it, just don't use it. All of my commands load and wait in the background.
My acaddoc.lsp:
(defun S::STARTUP()
(setvar "DIMASSOC" 2)
(command "edgemode" "1")
(command "taskbar" "0")
(command "expert" "1")
(load "fz")
(load "zz")
(load "atp")
(load "chl")
(load "enddwg")
(load "ImperialUnits")
(load "MetricUnits")
)
(princ)
Each item loaded is a command, but.
My "ZZ" command:
(defun c:zz ()
(command ".zoom" "e" ".qsave")
(princ)
)
(princ "\n zz.lsp is loaded. Type \"ZZ\" to zoom and save")
(princ)
(defun c:za ()
(command ".zoom" "a" ".qsave")
(princ)
)
(defun c:expl ()
(command ".explorer")
(princ)
)
(defun c:zp ()
(command ".zoom" "e" ".qsave")
(command ".zoom" "p")
(princ)
)
(defun c:rs ()
(command ".regen" ".qsave")
(princ)
)
(defun c:dbl ()
(command ".dimbaseline")
(princ)
)
(defun c:dsp ()
(command ".dimspace")
(princ)
)
(defun c:top ()
(command "-view" "o" "t");;;view from Top
(princ)
)
(defun c:fr ()
(command "-view" "o" "f");;;view from Front
(princ)
)
(defun c:back ()
(command "-view" "o" "ba");;;view from back
(princ)
)
(defun c:bottom ()
(command "-view" "o" "b");;;view from bottom
(princ)
)
(defun c:left ()
(command "-view" "o" "l");;;view from Left side
(princ)
)
(defun c:right ()
(command "-view" "o" "r");;;view from Right side
(princ)
)
(defun c:rv ()
(command ".revcloud")
(Command pause)
(princ)
)
(princ "\n revcloud.lsp is loaded. Type \"RV\" to run.")
(princ)
(defun c:sr ()
(command "_vscurrent" "r");;;current view Realistic
(princ)
)
(defun c:s3 ()
(command "_vscurrent" "3");;;current view 3D wireframe
(princ)
)
(defun c:s2 ()
(command "_vscurrent" "2");;;current view 2D wireframe
(princ)
)
(defun c:s3h ()
(command "_vscurrent" "h");;;current view 3D hidden
(princ)
)
(defun c:dml ()
(setvar "cmdecho" 0)
(setq SET-OLD-LAYER (getvar "clayer"))
(command "-layer" "s" "Dims" "")
(Command "ORTHO" "OFF")
(Command ".dimlinear")
(while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (command PAUSE))
(Command "ORTHO" "ON")
(setvar "clayer" SET-OLD-LAYER)
(princ)
)
HD
@HullDrafter wrote:
....
I have created a slew of macros and I have all of them load when AutoCAD starts everytime. If you don't want a command to be in a drawing, why not load it, just don't use it. All of my commands load and wait in the background.
My acaddoc.lsp:
....
(load "zz")
....Each item loaded is a command, but.
My "ZZ" command:
(defun c:zz ()
(command ".zoom" "e" ".qsave")
(princ)
)
....
Using (autoload) has the added advantage, compared to (load), that the commands become just as available, but the files are not actually loaded unless and until a command in them is called for -- they "wait in the background" without taking the time to load if they're never used. If you have a lot of such files, especially if they're significantly larger command definitions than these, that can save a noticeable amount of time in opening a drawing.
Since in the above scenario I assume there must be a zz.lsp file that contains the zz command definition, you can do it by replacing
(load "zz")
with
(autoload "zz" '("zz"))
You can even throw multiple command definitions into one shared .lsp file, and include all the command names in the file in that list at the end of the (autoload) function:
(autoload "mycommands" '("zz" "fz" "atp" "chl"))
All will be just as available, but the file won't load until any one of them is called for, and there will be fewer files to manage [though I can also imagine that some will prefer having each command in its own file for such purposes as finding the file more easily if you want to adjust the command definition].
Thanks for the help everyone. I have a lot of good advice here. I think we can control everything from the Acad.lsp and Acaddoc.lsp.
As an alternative to Kent's wonderful suggestion I present the following (autoload is too command line noisy for my taste):
Inside ACAD.lsp (or ACADDOC.lsp or MyMenu.MNL), declare the keystroke to load the routine and start the routine.
What happens here is only the keystroke is defined and the program is not loaded (very similar to autoload) until
called upon.
(defun c:AA () (load "AA")(c:AA)) ;brief description
Note when routine loads, the keystroke is redefined only if the first and third statements are exactly the same.
(defun c:AA () (load "ArcArrow")(c:AA)) ;brief description
When the first and third statements are not the same, the routine loads and will reload every time it is called.
This works well as a bypass to files that have been encrypted (FAS) where you desire another keystroke and do
not have access to the original unencrypted file. Autoload accomplishes this same thing with it's list at the end
(except for the reloading part).
(defun c:SS () (load "MatchProps")(c:MP)) ;brief description
Hope this helps.
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.