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

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2598
  • 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.
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12905
  • 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

  • Gator
  • Posts: 2598
  • 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.
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
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

  • Gator
  • Posts: 2598
  • 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
Civil3D 2020

MSTG007

  • Gator
  • Posts: 2598
  • 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 »
Civil3D 2020

dgorsman

  • Water Moccasin
  • Posts: 2437
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

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
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

  • Gator
  • Posts: 2598
  • 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
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
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

  • Gator
  • Posts: 2598
  • 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
("_>
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
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 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • 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.
Civil3D 2020

ChrisCarlson

  • Guest
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: 7526
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 11 x64 - AutoCAD /C3D 2023

Custom Build PC