Author Topic: ondocload lisp file for newbie  (Read 3939 times)

0 Members and 1 Guest are viewing this topic.

GISDUDE

  • Guest
ondocload lisp file for newbie
« on: July 07, 2012, 11:19:58 AM »
Hey all,
I'm a veteran autocad user (8years) and have used autolisp routines in various ways. I'm beginning to teach myself to create my own lisp routines.

My company is a small firm and it's only 2 guys in the CAD/GIS department. There is a file in the roaming directory that is labeled "ondocload.lsp". I understand that lisp file "connects" all our other lisp routines (probably 100 or so when I looked).

How does the docload connect with the other lisp files and when I start to add my own routines, how do I make sure they will be included?

Thanks all

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ondocload lisp file for newbie
« Reply #1 on: July 07, 2012, 01:26:19 PM »
Welcome to the Swamp :-)

I've never heard of the 'ondocload.lsp' file - this may be something specific to your company.

Usually, most users load programs via the ACADDOC.lsp, a file which will automatically load when a drawing is opened.
« Last Edit: July 07, 2012, 01:30:58 PM by Lee Mac »

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ondocload lisp file for newbie
« Reply #2 on: July 07, 2012, 02:06:15 PM »
I have a file a customized lisp file and I use it to autoload all lisp that I use. Something like:
Code: [Select]
(autoload "cut" '("cut"))
(autoload "bordlay" '("bordlay"))
(autoload "pdf" '("pdf"))
(autoload "usis" '("usis"))
.... etc
My file is under a custom directory, which is on my Support File Search Path in Acad.
I load this file from Autocad Installation Path \ Support \  acad.lsp.
So maybe your file is just the same.
I think this method is very easy way to migrate. After an upgrade, all I need to do is to edit (or create) acad.lsp, write (load "my_file.lsp") in it and add some directories in Suport File Search Path.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ondocload lisp file for newbie
« Reply #3 on: July 07, 2012, 06:09:44 PM »
I have a customized lisp file and I use it to autoload all lisp that I use...
...I load this file from Autocad Installation Path \ Support \  acad.lsp.

Just curious, why not simply place the autoload expressions directly in the ACADDOC.lsp / ACAD.lsp? Such files are reserved for user customisation and futhermore, migration is one step easier for you  :-)

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ondocload lisp file for newbie
« Reply #4 on: July 08, 2012, 04:37:35 AM »
Just curious, why not simply place the autoload expressions directly in the ACADDOC.lsp / ACAD.lsp? Such files are reserved for user customisation and futhermore, migration is one step easier for you  :-)
I guess I can, but it doesn't bother me since acad2007, so it becomes a habit.
I thought the OP is in the same situation, so he/she can reach to a  conclusion.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ondocload lisp file for newbie
« Reply #5 on: July 08, 2012, 06:05:59 AM »
To each his own I suppose  :-)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: ondocload lisp file for newbie
« Reply #6 on: July 09, 2012, 04:28:23 AM »
@GISDUDE: Did these explanations give you insight as to you question?

I'm guessing your ondocload.lsp is very close to Stefan's code in the 3rd post (perhaps using load instead of autoload). But your question was how to get your ondocload.lsp loading ... right?  ;)

Anyhoo, there's quite a few methods, but the most robust & portable one is to include a statement in the acaddoc.lsp file (this might be a file you have to create as it doesn't exist by default). Please never alter the existing acaddoc20##.LSP file. That one's ADesk's file and could change at any time due to updates / upgrades - effectively erasing your edits. The acaddoc.lsp and acad.lsp files are deemed to be your own and adesk will never touch them.

Assuming your ondocload.lsp is in a support folder, the following code in the acaddoc.lsp should be sufficient:
Code - Auto/Visual Lisp: [Select]
  1. (load "ondocload")
If the file isn't in the support folders, and for some reason you don't want to include it's folder in the support path, then you'll need to add it's path in that load statement.

Another point is if your load statement has no 2nd argument (as the sample above does), then loading a LSP file with an error in it will propagate the error into the file loading it. So if there's an error in the ondocload.lsp file, then the above will cause acaddoc.lsp to stop at the load statement. A way of getting around this is to include a 2nd argument:
Code - Auto/Visual Lisp: [Select]
  1. (load "ondocload" nil)
This way if there's an error, the load function simply returns the 2nd argument (in this case nil) and lisp continues to the next statement without erroring the whole acaddoc.lsp file. This might be why your ondocload.lsp is a separate file - to avoid other customizations failing to initialize if something else fails.

Other ways of including your file might be to add it to the StartUp suite (AppLoad command), though I'd not advise this as it tends to give strange results especially on shared folders. Or you could add the file as a lisp to be loaded in your CUI. Or add the load statement into a MNL file named the same (and in the same folder) as your CUI(x)/MNU file. My personal favourite  is the MNL idea, since it ties nicely with my custom toolbars/menus/ribbon panels - i.e. all I need to do to "install" my LSPs is to load my CUI (which I'd have done anyway to add the toolbars/etc. through the CUI command or MenuLoad command). The MNL file works much the same as the acaddoc.lsp, though it need not be in a support folder - only in the same folder as its CUI.

As for using load / autoload - it depends on your preference / scenario. Load immediately loads the LSP/FAS/VLX file, while autoload creates a temporary defun which calls the load only when the command is executed. Note though that the built-in autoload has some issues with paths, I'd recommend that if you use it all your LSP files need to be in a folder under your support paths.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

GISDUDE

  • Guest
Re: ondocload lisp file for newbie
« Reply #7 on: July 10, 2012, 01:17:41 AM »
Hey all,

Thanks for the responses.  The file I'm referring to is the "ondocload.lsp" file. This is a file that came with a 3rd pary plugin for autocad (TOOLPAC) from DOTSOFT.

Please forgive, but I think I confused the 2 types of files, and please correct me. The acaddoc.lsp file is used for ALL THE THE LISP routines that we have. Therefore in order to add any more customized lisp files, I think I need to place those files in the directory that the acaddoc.lsp file is in, right? So, whatever keyboard shortcuts you have for a lisp file, those need to be in the same directory, OTHERWISE, I will need to APPLOAD the lisp file from the dialog box. I'm trying not to APPLOAD every lisp routine. For instance, I frequently have to get areas and perimeters for polygons and label them in the polygon. In the past I would just type GA (stands for GetArea) and it would label the polygon with the perimeter, that I selected. Now the company I'm at has a different setup. Now I have to APPLOAD the lisp file. It's just 2 extra steps, but it does bog me down.

Thanks again for all the help, and I'll keep experimenting.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: ondocload lisp file for newbie
« Reply #8 on: July 10, 2012, 02:20:13 AM »
The acaddoc.lsp file is used for ALL THE THE LISP routines that we have.
Not necessarily, as per my previous post there are many othre ways as well.
Therefore in order to add any more customized lisp files, I think I need to place those files in the directory that the acaddoc.lsp file is in, right?
You don't need to, as long as it's inside one of the folders on your support path (those listed in the Options dialog's Files tab -- Support File Search Path. The other LSP files may be anywhere in those folders as well - acad searches through all of them. You could even have the LSP files in folders not part of those listed, but then you need to specify their paths in the load call.
It's only when you use MNL files instead of ACADDOC.LSP to load your own when they need to be in the same folder as the CUI. E.g. say you've got your own custom MyMenus.CUI file, then you create a MyMenus.MNL file in the same place. Then inside that you place the statements to load your other LSP files either immediately (load "Filename") or when command issued (autoload "FileName" '("command1" "command2" ... "commandN"))
So, whatever keyboard shortcuts you have for a lisp file, those need to be in the same directory
Actually no, your keyboard shortcuts are saved in an ACAD.PGP file - this one's also in one of the support folders (usually under the C:\Users\<UserName>\AppData\Roaming\Autodesk\AutoCAD ####\R##.#\enu\Support folder). You can edit this file in Notepad if you wish, or use the Express tool AliasEdit.
For instance, I frequently have to get areas and perimeters for polygons and label them in the polygon. In the past I would just type GA (stands for GetArea) and it would label the polygon with the perimeter, that I selected.
In which case you add a GA shortcut to the GetArea command - which should be inside a LSP file with something starting like
Code - Auto/Visual Lisp: [Select]
  1. (defun c:GetArea ...
Thus you have to load / autoload that LSP file for the GetArea command to be available, otherwise you'll get an Unknown Command error.

BTW, GA defaults to the GATTE (Global Attribute Edit) command on my ACad 2012 ... you can easily overwrite that shortcut by placing your version lower down in the PGP file (the AliasEdit command will do so for you).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

laidbacklarry

  • Guest
Re: ondocload lisp file for newbie
« Reply #9 on: July 10, 2012, 07:54:48 AM »
Don't know if there's any relevance, but ON_DOC_LOAD is the Bricscad equivalent of ACADDOC.

GISDUDE

  • Guest
Re: ondocload lisp file for newbie
« Reply #10 on: July 10, 2012, 02:35:44 PM »
@laidbacklarry,
You're correct...sorry I didn't mention it beforehand.

I did get some good info from the group, however.