TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MSTG007 on May 20, 2019, 07:10:26 AM

Title: Cui - LISP Load Question
Post by: MSTG007 on May 20, 2019, 07:10:26 AM
I have this routine loaded within a CUI under LISP Files.
If a routine is accidently not there, the file will not load any of the routines below.
How can I get keep loading even when a file is not there?

Code: [Select]
(defun C:cui_Loader()
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\85x11_L.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\85x11_P.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\11X17_L.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\11X17_P.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\22X34_L.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\22X34_P.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\24X36_L.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\24X36_P.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\30X42_L.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\30X42_P.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\36X48_L.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\36X48_P.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-10.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-20.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-30.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-40.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-50.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-60.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-80.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-100.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-200.lsp")
(load "\\\\Server1\\Autodesk\\CUI\\Ribbon\\1-500.lsp")
(princ))
(C:cui_Loader)

Thanks for any help :)
Title: Re: Cui - LISP Load Question
Post by: gile on May 20, 2019, 07:54:11 AM
You can create a .MNL fil with the same name as your CUIX file (e.g. Foo.cuix, Foo.mnl) in which you just paste the (load ...) expressions.
The MNL file will be loaded and executes when the CUIX file is loaded.
Title: Re: Cui - LISP Load Question
Post by: Master_Shake on May 20, 2019, 08:08:00 AM
Instead of loading via lisp, use the built-in loader within the CUIx utility
Title: Re: Cui - LISP Load Question
Post by: MSTG007 on May 20, 2019, 08:11:02 AM
So basically load each lisp in the loader and not an overall loading file. I can try that.
Title: Re: Cui - LISP Load Question
Post by: tombu on May 20, 2019, 09:47:06 AM
Many threads on many forums dedicated to options for loading lisp. First thing would be to keep all your lisp in folders in the Support File Search Path to avoid ever having to include paths like that.
Having a large number of lisp loading every time you open a drawing you may not need seems unnecessary.
You seem to have 10 lisp listed for setting scale.  Why not use one lisp with an argument like
Code: [Select]
(defun scale1to (x / temp)where
Code: [Select]
(scale1to 50)would replace the macro for 1-50.
Consider using the lisp function autoload (https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-421B36DE-38EA-4161-9768-01647B5492E8-htm.html) or just have it autoload in the macro like:
Code: [Select]
(or (scale1to)(load "scale1to.lsp")) (scale1to 50) which would load the lisp if it wasn't already loaded and then set the scale to 1:50. This is how 90% of mine are loaded. 
Title: Re: Cui - LISP Load Question
Post by: MSTG007 on May 20, 2019, 10:00:31 AM
What are your thoughts on demand load opposed to loaded all these files in every time a drawing opens? I would think it would be harder to manage. Just a question.
Title: Re: Cui - LISP Load Question
Post by: tombu on May 20, 2019, 12:45:16 PM
What are your thoughts on demand load opposed to loaded all these files in every time a drawing opens? I would think it would be harder to manage. Just a question.
While I have a small group of daily used lisp functions loaded with acaddoc.lsp every time a drawing opens and a few in acad.lsp to make profile modifications as necessary most of my routines are demand loaded either in the CUI command macro or with a autoload function call in acaddoc.lsp.

I have a large number of custom CUI commands that require lisp to be loaded.  If there's ever a conflict when using one of these commands from another lisp that may be using the same global variable or function name I'd be able to find and correct the conflict right away.  I use a lot of downloaded lisp and these things happen.  My PC's performance isn't as good as I'd prefer so loading all the lisp I could ever possibly use would degrade that performance more than I could put up with.
Title: Re: Cui - LISP Load Question
Post by: dgorsman on May 20, 2019, 01:09:49 PM
Look into the help for the (load ...) function.  It has an optional argument, when used a failed load doesn't (exit) it returns that optional argument.  By checking the return value you can provide some feedback on exactly *what* failed to load.
Title: Re: Cui - LISP Load Question
Post by: tombu on May 20, 2019, 03:25:56 PM
I have this routine loaded within a CUI under LISP Files.
If a routine is accidently not there, the file will not load any of the routines below.
How can I get keep loading even when a file is not there?
Thanks for any help :)
This will test and load all those files that are found:
Code: [Select]
(defun cui_Loader (lspfile / fpath)
  (setq fpath (strcat "\\\\Server1\\Autodesk\\CUI\\Ribbon\\" lspfile))
  (or (findfile fpath)(load fpath))
  (princ)
)
(cui_Loader "85x11_L.lsp")
(cui_Loader "85x11_P.lsp")
(cui_Loader "11X17_L.lsp")
(cui_Loader "11X17_P.lsp")
(cui_Loader "22X34_L.lsp")
(cui_Loader "22X34_P.lsp")
(cui_Loader "24X36_L.lsp")
(cui_Loader "24X36_P.lsp")
(cui_Loader "30X42_L.lsp")
(cui_Loader "30X42_P.lsp")
(cui_Loader "36X48_L.lsp")
(cui_Loader "36X48_P.lsp")
(cui_Loader "1-10.lsp")
(cui_Loader "1-20.lsp")
(cui_Loader "1-30.lsp")
(cui_Loader "1-40.lsp")
(cui_Loader "1-50.lsp")
(cui_Loader "1-60.lsp")
(cui_Loader "1-80.lsp")
(cui_Loader "1-100.lsp")
(cui_Loader "1-200.lsp")
(cui_Loader "1-500.lsp")
(princ)
It's also an example of one lisp that can be used with many arguments like one that could handle all your scales.
Title: Re: Cui - LISP Load Question
Post by: MSTG007 on May 20, 2019, 03:36:01 PM
Thank you for sharing this. Its simple and makes sense. Saves a lot of headaches lol.
Title: Re: Cui - LISP Load Question
Post by: BIGAL on May 21, 2019, 01:05:48 AM
For me it looks like a plot routine so why not use a dcl with a list pick the plot routine then load the lisp required.

Version 2 is like 1 pick the plot size pass that to one lisp that uses a list look up for plot size then read the correct variables to be used only 1 lisp for all sizes.

Post a couple if happy so can have a look at what is going on.

I had two floors of drafters with printers / plotters on 3 floors all was automatic based on user's ID sent to printer closest and relevant colour/mono.
Title: Re: Cui - LISP Load Question
Post by: MSTG007 on May 21, 2019, 06:59:42 AM
Just to give you guys more information. The routines are tied to a custom ribbon. There are 85 routines that are individually loaded when the CUI is loaded. (I just used the plot scales and page setups as an example to get me to the right direction. lol. However, there are some really interesting ideas on this thread. ;)
Title: Re: Cui - LISP Load Question
Post by: Master_Shake on May 21, 2019, 08:19:22 AM
Instead of 85 different plotting routines, why not merge them into a more efficient, single-source lisp routine?
Title: Re: Cui - LISP Load Question
Post by: tombu on May 21, 2019, 10:22:55 AM
Instead of 85 different plotting routines, why not merge them into a more efficient, single-source lisp routine?
Exactly!

I use Lee Mac's Steal from Drawing (http://www.lee-mac.com/steal.html) for importing Layouts, Plot Styles, and everything else. I use one other lisp for deleting Plot Styles first that I wish to update from a template.  Everything I've seen shouldn't take more than a couple routines and they've probably all been written already.
Title: Re: Cui - LISP Load Question
Post by: ronjonp on May 21, 2019, 10:29:00 AM
I use a template with predefined pagesetups along with sheet set manager and or CAB's plottabs routine. IMO, 85 routines for plotting is a bit crazy!  :-P

Title: Re: Cui - LISP Load Question
Post by: MSTG007 on May 21, 2019, 10:32:08 AM
lol.... I think I need make sure you guys do not think I am crazy. I agree 85 'routines' for plotted is nuts. The ribbon I have created is not just for plotting but other tools as well. I just need those to load in. I have a lot of commands on the ribbon. lol.

But again, like you guys are suggesting, I would definitely use Lees Steal routine, it is awesome.
Title: Re: Cui - LISP Load Question
Post by: MP on May 21, 2019, 10:52:47 AM
Casual observation suggests 2 functions that take 85+ arguments between them would be more efficient.
Title: Re: Cui - LISP Load Question
Post by: dgorsman on May 21, 2019, 11:01:35 AM
Casual observation suggests 2 functions that take 85+ arguments between them would be more efficient.

"Change the data, not the code."
Title: Re: Cui - LISP Load Question
Post by: MSTG007 on May 21, 2019, 11:03:43 AM
Just curious. Is it bad practice to combined multiple routines into one file, rather than a file for each routine?
Title: Re: Cui - LISP Load Question
Post by: MP on May 21, 2019, 11:25:48 AM
IME what's "bad practice" is duplicated / copied logic -- it's unnecessarily maintenance and trouble shooting heavy. Regarding one file or multiple files -- per my previous post -- it would appear 2 functions taking multiple arguments would suffice. If said functions are ambitious (doesn't appear so) or significantly different (i.e. prone to independent update / maintenance) 2 files might be the better option.
Title: Re: Cui - LISP Load Question
Post by: MP on May 21, 2019, 11:49:01 AM
"Change the data, not the code."

this