Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Loading .lsp files

8 REPLIES 8
Reply
Message 1 of 9
wsargent
6965 Views, 8 Replies

Loading .lsp files

It was decided the our company would use the acaddoc.lsp file as a load file and each lisp command would be in its own document. Currently the load uses absolute pathing. Is there a way to relative path the load command within a lisp file or is there only the absolute path and no path options?

 

Currently the custom lisp is in a folder on the standards drive named 'lisp' and the individual commands are in a sub folder named 'command lisps' so the current load for our fillet zero command looks like this:

     (load "n:/2012-config/lisp/Command lisps/FZ.lsp")

 

If we removed the sub folder I know we could load the commands like this:

     (load "FZ.lsp")

 

But one of the committee members wants the suborder...

 

Since the company currently maintains multiple versions of AutoCAD to comply with contracts it would be nice not to have to modify the paths to copy any updates across the different platforms.

 

Thanks in advance.

__________

AutoCAD Civil 3D 2016 SP3.0, built on: AutoCAD 2016 SP1, Map 3D 2016 SP2
Dell Percision T5810: MS Windows 10 Pro; Intel Xeon CPU E5-1620 v3 @ 3.50 GHz, 16.00 GB RAM, NVIDIA K2200 4.00 GB Memory
8 REPLIES 8
Message 2 of 9
Kent1Cooper
in reply to: wsargent


@wsargent wrote:

It was decided the our company would use the acaddoc.lsp file as a load file and each lisp command would be in its own document. Currently the load uses absolute pathing. Is there a way to relative path the load command within a lisp file or is there only the absolute path and no path options?

 

Currently the custom lisp is in a folder on the standards drive named 'lisp' and the individual commands are in a sub folder named 'command lisps' so the current load for our fillet zero command looks like this:

     (load "n:/2012-config/lisp/Command lisps/FZ.lsp")

 

If we removed the sub folder I know we could load the commands like this:

     (load "FZ.lsp")

 

But one of the committee members wants the suborder...

....


If I'm understanding the issue correctly, I would suggest that you simply put

n:/2012-config/lisp/Command lisps

in the Support File Search Path list, in addition to

n:/2012-config/lisp

being there, and just use the (load "filename") [or (autoload)] approach, without a path.

 

That way, individual commands' definitions will be found in the /Command lisps sub-folder, but anything that's not an individual-command file and therefore not that far down, but is in the /lisp sub-folder, will still be found when needed.  For whatever reasons someone "wants the suborder," I would hope looking at the Search Path list on a given installation would "tell" them what they need to know about which files are being used.

 

Is the "custom lisp" in the .../lisp sub-folder something that contains your command definitions, in addition to their being defined in individual-command files in the .../Command files sub-folder?  If so, you would want to make sure that none of the command definitions is different in the two files.  If there is any such difference in definition, the definition in effect at any given time will be the one in whichever file was most recently loaded.

 

If you have different versions that require different definitions of certain commands, presumably you have different such file paths that can be listed appropriately in Options within each program.  If any of the commands are universal and don't need to be defined differently by AutoCAD version, they could go in another sub-folder without a version number in its path, and that could be put into the Search Path list in all installations.

Kent Cooper, AIA
Message 3 of 9
wsargent
in reply to: Kent1Cooper

'suborder' was a typo/spell check error I meant sub-folder.

 

I hope this is a better description: The company's custom acaddoc.lsp file is saved on the network on a limited access drive by program release year. So currently there are three config folders (2009-config, 2011-config, and 2012-config) each containing the network files for that years program.

 

In the File Search Path there is a path (at the top of the list) for n:/[year]-config/lisp.

 

The lisp folder contains two items: the acaddoc.lsp and a sub-folder named "Command lisps" with each custom command defined in a separate file.

 

The acaddoc.lsp contains a list of loads of all the lsp file in the Command lisps folder. So it just contains 26 lines of: (load "n:/[year]-config/lisp/Command lisps/filename.lsp") lines, with no commands defined.

 

Because these files are in two different folders duplicated for each year of the program I was hoping there was a relative path option like with external references so when changes are made it can be just a copy and paste.

 

It sounds like there is no such thing, but by adding the additional Support File Search Path you can get the same result using the autoload approach.

 

Thanks

__________

AutoCAD Civil 3D 2016 SP3.0, built on: AutoCAD 2016 SP1, Map 3D 2016 SP2
Dell Percision T5810: MS Windows 10 Pro; Intel Xeon CPU E5-1620 v3 @ 3.50 GHz, 16.00 GB RAM, NVIDIA K2200 4.00 GB Memory
Message 4 of 9
Rick-K
in reply to: wsargent

The paths cannot be "relative" as far as I know.

 

As Kent stated if you goto Options and add the path you have your lisps in and you will not need to have the path in your acaddoc.lsp.

 

You just need to change path for each new release of autocad since you have a new folder for each release.

 

If you use "autoload" instead of "load" the lisps will not be loaded into memory until you need them.

Instead of loading all of them every time.

Here is the format.

(autoload "burst" '("burst"))

 

This autoloads burst.lsp.

 

Notice I do not even have .lsp in the line because acad knows to look for lisps.

 

Rick

Message 5 of 9
wsargent
in reply to: Rick-K

So I understand the language...

 

(autoload "burst" '("burst"))

 

Autoload tells AutoCAD to wait till the command is asked for before loading it.

 

"burst" is... what activates the command?

 

'("burst") is the .lsp file name?

__________

AutoCAD Civil 3D 2016 SP3.0, built on: AutoCAD 2016 SP1, Map 3D 2016 SP2
Dell Percision T5810: MS Windows 10 Pro; Intel Xeon CPU E5-1620 v3 @ 3.50 GHz, 16.00 GB RAM, NVIDIA K2200 4.00 GB Memory
Message 6 of 9
scot-65
in reply to: wsargent

Our method of loading routines

 

Inside our ACAD.lsp or acaddoc.lsp file is a line that says:

 (if (findfile "My_Util.lsp") (load "My_Util"))

[as the example]

 

Now, what is inside the "My_Util.lsp" file is the following:

(defun c:AA () (load "AA") (c:AA) ) ;brief description of AA

(defun c:BB () (load "BB") (c:BB) ) ;brief description of BB

...

Continue with all stand-alone file command type lisps.

What this does is to define the keystroke "seed" when the editor starts

up, and when the keystroke is first executed, the program is loaded at

that time, overtakes the "seed" command, and begins the program.

I have over 200 lines in my utility file.

 

Of course command names might differ from file name, so do yourself

a favor and try to match these. It will save you grief down the road.

 

If there are more than one command inside a file, do yourself another

favor and place each command in separate files. If you cannot, dump

the entire file content into the acad/acaddoc file and abandon the original

file. Give to next person to figure it out.

 

If more than one routine accesses a function or subroutine, place that

subroutine inside the acad/acaddoc lsp file (or use MNL). Make note inside

the file header/description that the program access an outside subroutine.

 

I do not use autoload because of the command line noise.

 

The file called "AA.lsp" is in a folder that is declared in the support path.

The file called "My_Util.lsp" is in the "Support" folder that our CUI file is located.

For each folder that contains stand-alone file commands, declare a

support path to these folders. "Hard Pathing" is not the method to use.

 

For each new stand-alone command routine that you add to your library, simply

place file in designated folder, then edit the utility file by adding a line, and you

are good to go!

 

Now you can make a hard copy of the utility file and know what commands

are available (or for use to create a custom command handout) without having

to muddle through the acad/acaddoc file.

 

Hope this helps.


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


Message 7 of 9
Kent1Cooper
in reply to: wsargent


@wsargent wrote:

So I understand the language...

 

(autoload "burst" '("burst"))

 

Autoload tells AutoCAD to wait till the command is asked for before loading it.

 

"burst" is... what activates the command?

 

'("burst") is the .lsp file name?


Read up in the AutoLISP Reference about (autoload).  The first argument is the file name [with or without the .lsp or .vlx or other appropriate filetype ending], and the one or more inside the inner parentheses is/are the command name(s) defined in that file.  A file can contain more than one command, so you can say
 

(autoload "filename" ("command1" "command2" "command3"))

 

Unlike scot-65, I do prefer the (autoload) approach except for things I know I will almost certainly use in almost every drawing -- those I either have defined right in acaddoc.lsp, or overtly (load)ed by it.

 

Every drawing takes less time to open up if it doesn't need to load a whole litany of command definitions, even if they're only those one-liners, whether or not they will ever be used.  The only "command line noise" occurs on only the first use of only the first command called for from a given file.  If you call for "command2" in the above scenario, yes, an "Initializing" word flies past as it loads the file and invokes that command, but only the first time you use it.  But if and when you later call for "command1" or "command3," there will be no "noise" at all [as there would be in the every-command-in-an-individual-file approach], because they're already loaded by the earlier calling for "command1."

 

I would, however, do yourself the favor of combining definitions of only related commands within a single file, partly just so that the file name can have some discernible relationship to what's defined in it, for identification when you're looking at a folder of .lsp files.

 

Another advantage:  with scot-65's approach, when you make a new command definition file, presumably you would need to add this to your utility file:

 

(defun c:MM () (load "MM") (c:MM) )

 

whereas with the (autoload) approach, you need to add just this much to acaddoc.lsp

 

(autoload "MM" ("MM"))

 

and you don't need the middle-man utility file at all.

Kent Cooper, AIA
Message 8 of 9
martti.halminen
in reply to: wsargent


@wsargent wrote:

It was decided the our company would use the acaddoc.lsp file as a load file and each lisp command would be in its own document. Currently the load uses absolute pathing. Is there a way to relative path the load command within a lisp file or is there only the absolute path and no path options?

 

Currently the custom lisp is in a folder on the standards drive named 'lisp' and the individual commands are in a sub folder named 'command lisps' so the current load for our fillet zero command looks like this:

     (load "n:/2012-config/lisp/Command lisps/FZ.lsp")

 


 

The LOAD function itself only accepts full paths or bare filenames (-> searches the library paths).

But it would be trivial to define your own loading function in the acaddoc.lsp file where you could use relative paths:
(setq *lisp-load-root* "n:/2012-config/lisp/Command lisps/")

(defun my-load (partial-path)
  ;; Calls AutoLISP LOAD with the value of *lisp-load-root* added to the path
  (load (strcat *lisp-load-root* partial-path)))

 

After this just change your LOAD calls correspondingly:
(my-load "FZ.lsp")

 

and, when moving to another version, just correct the value of *lisp-load-root* accordingly.

 

--

 

 

Message 9 of 9
Rick-K
in reply to: martti.halminen

Yes... What they said.

 

I personally write 1 routine in each lisp file just to make it easier to find when I need to edit them.

 

My autoload probably has 40+ different lines/lisps but it doesnt seem to hurt anything.

 

Rick

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost