TheSwamp

CAD Forums => CAD General => Topic started by: MSTG007 on February 20, 2017, 11:11:08 AM

Title: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 20, 2017, 11:11:08 AM
I am trying to see if I can create a macro that will run a lisp routine that I have barried several folders deep.

Code: [Select]
(load "Support Folder\\2\\3\\4\\Z2S - Zoom to Structure.LSP")(C:z2s)
I know I can get it to work if I add the full address, but did not know if it would work like the above.

thanks for the help.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: Lee Mac on February 20, 2017, 12:34:17 PM
As far as I'm aware, not possible without the file either residing in the support path or the full path to the file is provided.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 20, 2017, 12:36:30 PM
Ok. That answers that question. Thanks for the info Lee. It was just a thought to see if it would.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: roy_043 on February 20, 2017, 02:13:46 PM
This (http://www.cadtutor.net/forum/showthread.php?76081-Support-File-Search-Path&s=f96033615177d0bc8b99f2245c67eed0&p=513429&viewfull=1#post513429) suggests that the findfile function can find files in subfolders in the search path. In BricsCAD this also applies to the load function.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 20, 2017, 02:46:08 PM
Interesting... I gotta try this out. Thank you
Title: Re: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 20, 2017, 03:14:52 PM
I tested it out and it does what I need it to do.

Code: [Select]
(findfile "_Routine_Library\\Z2S - Zoom to Structure\\Z2S - Zoom to Structure.LSP")(load "Z2S - Zoom to Structure")(C:z2s)
I have the main support path loaded and then there are folders under that with routines. Thanks for all the help.

For my next step was to try to activate this via the CUI or a Tool Palette button, but in either case I get the following:

Code: [Select]
Command:
(findfile "_Routine_Library

Not sure why it does that.

If I copy and paste this to the command prompt; it works.

Code: [Select]
(findfile "_Routine_Library\\Z2S - Zoom to Structure\\Z2S - Zoom to Structure.LSP")(load "Z2S - Zoom to Structure")(C:z2s)
Title: Re: Calling Routines in a Subfolder of the support path
Post by: dgorsman on February 21, 2017, 10:27:53 AM
My recommendation - write your own nested search function in LISP.  That way, if you don't expect file locations to change drastically you can also include search caching (no point searching for the same thing over and over after it's already been found).
Title: Re: Calling Routines in a Subfolder of the support path
Post by: roy_043 on February 21, 2017, 12:57:03 PM
@MSTG007:
This code surprises me:
Code: [Select]
(findfile "_Routine_Library\\Z2S - Zoom to Structure\\Z2S - Zoom to Structure.LSP")(load "Z2S - Zoom to Structure")(C:z2s)

Either this works:
Code: [Select]
(load "_Routine_Library\\Z2S - Zoom to Structure\\Z2S - Zoom to Structure.LSP")(C:z2s)Or you would have to use this:
Code: [Select]
(load (findfile "_Routine_Library\\Z2S - Zoom to Structure\\Z2S - Zoom to Structure.LSP"))(C:z2s)
I am not sure why calling this from a CUI fails. Try switching to forward slashes.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 21, 2017, 01:38:09 PM
I tried the forward slash. No such luck.

Code: [Select]
Command: (load (findfile "_Routine_Library/Z2S - Zoom to Structure/Z2S - Zoom to Structure.LSP"))(C:z2s) ; error: bad argument type: stringp nil
Title: Re: Calling Routines in a Subfolder of the support path
Post by: roy_043 on February 22, 2017, 03:59:24 AM
If folder A is in a search path folder all this works in BricsCAD:

Command Bar entry:
Code: [Select]
(findfile "A\\B\\Name with spaces.lsp")
(findfile "A/B/Name with spaces.lsp")
(load "A\\B\\Name with spaces.lsp")
(load "A/B/Name with spaces.lsp")

CUI Macro's
Code: [Select]
(Load "A\\B\\Name with spaces.lsp")(c:LoadTest)
(Load "A/B/Name with spaces.lsp")(c:LoadTest)

I don't know why this does not work in AutoCAD.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 22, 2017, 07:09:10 AM
Its weird, maybe its the version of 2016 I am using...


Code: [Select]
Command: *Cancel*
Command: *Cancel*
Command: *Cancel*
Command: *Cancel*
Command: (findfile "_Routine_Library\\MT2ML - MText to Mleader\\MT2ML - MText to Mleader.LSP")(Load "_Routine_Library\\MT2ML - MText to Mleader\\MT2ML - MText to Mleader.LSP")\\MT2ML
Select source text: -
*Invalid selection*
Expects a single object.
Select source text: MText
*Invalid selection*
Expects a single object.
Select source text: to
*Invalid selection*
Expects a single object.
Select source text: Mleader.LSP")
*Invalid selection*
Expects a single object.
Select source text: ; error: bad argument type: lentityp nil
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]: *Cancel*
Command: (load "
("_>
("_> _Routine_Library
("_>
("_> Z2S - Zoom to Pipe Network Structure
("_>
Title: Re: Calling Routines in a Subfolder of the support path
Post by: ronjonp on February 22, 2017, 09:21:08 AM
Why don't you just add your subfolders to the support paths? Or you could use Lee's directory files (http://www.lee-mac.com/getallfiles.html) routine to load them.

Something like this:
Code - Auto/Visual Lisp: [Select]
  1. (foreach lisp (lm:directoryfiles "C:\\MYLispFiles" "*.lsp" t) (load lisp))
Title: Re: Calling Routines in a Subfolder of the support path
Post by: MSTG007 on February 22, 2017, 09:31:53 AM
Mr Ron, because we have a lisp routine in each folder. For the purpose of revisions to that routine, I have a void type folder that I can back it up at.

I think the real way to attack it even though its more work is to create a master routine.

Code: [Select]
(defun c:Main_Routine ()

(defun c:CLC()
  (findfile "_Routine_Library\CLC - Change Selected\CLC - Change Selected.LSP")(load "CLC - Change Selected.lsp")(C:CLC))

(defun c:DEMO()
  (findfile "_Routine_Library\DEMO - Demo Selection\DEMO - Demo Selection.LSP")(load "DEMO - Demo Selection.lsp")(C:DEMO))

(defun c:DPG()
  (findfile "_Routine_Library\DPG - Delete Duplicate Points\DPG - Delete Duplicate Points.LSP")(load "DPG - Delete Duplicate Points.lsp")(C:DPG))

(princ)


In my CUI and macro button I can now call the routines from that and it does work. Somewhat of a pain, but it does work.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: ChrisCarlson on February 22, 2017, 09:49:33 AM
Personally, I would create a master routine file. This has several benefits, the main being that you can reuse subroutines, i.e. a single error trapping, single routine to select objects, etc.
Title: Re: Calling Routines in a Subfolder of the support path
Post by: ronjonp on February 22, 2017, 10:02:36 AM
Mr Ron, because we have a lisp routine in each folder. For the purpose of revisions to that routine, I have a void type folder that I can back it up at.

I think the real way to attack it even though its more work is to create a master routine.

Code: [Select]
(defun c:Main_Routine ()

(defun c:CLC()
  (findfile "_Routine_Library\CLC - Change Selected\CLC - Change Selected.LSP")(load "CLC - Change Selected.lsp")(C:CLC))

(defun c:DEMO()
  (findfile "_Routine_Library\DEMO - Demo Selection\DEMO - Demo Selection.LSP")(load "DEMO - Demo Selection.lsp")(C:DEMO))

(defun c:DPG()
  (findfile "_Routine_Library\DPG - Delete Duplicate Points\DPG - Delete Duplicate Points.LSP")(load "DPG - Delete Duplicate Points.lsp")(C:DPG))

(princ)


In my CUI and macro button I can now call the routines from that and it does work. Somewhat of a pain, but it does work.
Lee's directory files & load like the example above is far simpler IMO. Why don't you use Dropbox or something if you're concerned about versions?
I'm not sure why you need to create 'master' file when one is available already (http://www.lee-mac.com/getallfiles.html).
Title: Re: Calling Routines in a Subfolder of the support path
Post by: dgorsman on February 22, 2017, 10:15:06 AM
Personally, I would create a master routine file. This has several benefits, the main being that you can reuse subroutines, i.e. a single error trapping, single routine to select objects, etc.

And as seen, trying to mix search paths, LISP, and macro code is PITA to set up.  Not to mention updating later if something changes.

But I would recommend verbose command names such as "ChangeSelected" rather than "CLC".  Easier to recognize, less chance of conflict/overriding something else.  If you want a 2 or 3 letter alias, use the PGP.