Author Topic: Calling Routines in a Subfolder of the support path  (Read 335 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Calling Routines in a Subfolder of the support path
« 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.
Autodesk Infrastructure Design Suite 2016

Lee Mac

  • Seagull
  • Posts: 11623
  • AutoCAD 2015 Windows 7 London, England
Re: Calling Routines in a Subfolder of the support path
« Reply #1 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.

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Re: Calling Routines in a Subfolder of the support path
« Reply #2 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.
Autodesk Infrastructure Design Suite 2016

roy_043

  • Swamp Rat
  • Posts: 1415
  • BricsCAD 16
Re: Calling Routines in a Subfolder of the support path
« Reply #3 on: February 20, 2017, 02:13:46 pm »
This suggests that the findfile function can find files in subfolders in the search path. In BricsCAD this also applies to the load function.

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Re: Calling Routines in a Subfolder of the support path
« Reply #4 on: February 20, 2017, 02:46:08 pm »
Interesting... I gotta try this out. Thank you
Autodesk Infrastructure Design Suite 2016

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Re: Calling Routines in a Subfolder of the support path
« Reply #5 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)
« Last Edit: February 20, 2017, 03:24:42 pm by MSTG007 »
Autodesk Infrastructure Design Suite 2016

dgorsman

  • Water Moccasin
  • Posts: 2171
Re: Calling Routines in a Subfolder of the support path
« Reply #6 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).
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

roy_043

  • Swamp Rat
  • Posts: 1415
  • BricsCAD 16
Re: Calling Routines in a Subfolder of the support path
« Reply #7 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.

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Re: Calling Routines in a Subfolder of the support path
« Reply #8 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
Autodesk Infrastructure Design Suite 2016

roy_043

  • Swamp Rat
  • Posts: 1415
  • BricsCAD 16
Re: Calling Routines in a Subfolder of the support path
« Reply #9 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.

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Re: Calling Routines in a Subfolder of the support path
« Reply #10 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
("_>
Autodesk Infrastructure Design Suite 2016

ronjonp

  • Needs a day job
  • Posts: 6145
Re: Calling Routines in a Subfolder of the support path
« Reply #11 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 routine to load them.

Something like this:
Code - Auto/Visual Lisp: [Select]
  1. (foreach lisp (lm:directoryfiles "C:\\MYLispFiles" "*.lsp" t) (load lisp))
« Last Edit: February 22, 2017, 09:26:18 am by ronjonp »

Windows 10 x64 - AutoCAD 2017

Custom Build PC

MSTG007

  • Water Moccasin
  • Posts: 1863
  • I can't remeber what I already asked! I need help!
Re: Calling Routines in a Subfolder of the support path
« Reply #12 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.
Autodesk Infrastructure Design Suite 2016

Master_Shake

  • Swamp Rat
  • Posts: 1148
Re: Calling Routines in a Subfolder of the support path
« Reply #13 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.

ronjonp

  • Needs a day job
  • Posts: 6145
Re: Calling Routines in a Subfolder of the support path
« Reply #14 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.

Windows 10 x64 - AutoCAD 2017

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2171
Re: Calling Routines in a Subfolder of the support path
« Reply #15 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}