Maybe I'm breaking a rule here, but I ran into someting today and the same thing seems to hapen to different programs, so I have a question regarding this observation.
Here is what I am trying to do:
Simply put a Lisp tool on the Block Authoring Palettes that launches Explorer to a folder (expressed as a variable). I have 4 folders that I reference all the time and I'd like to have a button right in the block editor (I spend most of my day in there) to launch Explorer to one of these four folders. I am creating 4 tools using the same code with separate variables being keyed by the tools to launch the lisp and execute according to the variable.
What I have found is that none of my code will allow me to set a path through lisp directly on the tool palette.
I often do things like this for other tools...
^C^C(setq dblk "165_FBBED_01.dwg" )(load "165POI")
That simple line on the tool palette sets the variable to which dynamic block I want to insert and then executes the lisp that handles insertion and modification of my dynamic block. It works flawlessly and I do this with dozens of variations.
I am trying to do the following now:
^C^C(setq DIR_PATH "C:\\CAD\\TGW")EASD
I get the following at the comand line:
(setq DIR_PATH "C:
Here is the program as modified my me...
(Defun C:EASD ();from CADalyst, Steven LaKose 10-11-2009
(Setvar "Cmdecho" 0)
(Command "Shell"
(Strcat
"Explorer /n,/e," ;Explorer, New Window, use Explorer View
(Chr 34) ;Quote marks
DIR_PATH ;Path I want to explicitly set
(Chr 34) ;Quote marks
) ;Close Strcat
) ;Close Command
(Princ)
) ;Close Defun on C:EASD
Here is the program as it origially appeared on cadtips.CADylist.com...
;========= Explorer to AutoSave Directory
(Setvar "Cmdecho" 0)
(Command "Shell"
(Strcat
"Explorer /n,/e," ;Explorer, New Window, use Explorer View
(Chr 34) ;Quote marks
(getvar "savefilepath") ;Current drive and folder
(Chr 34) ;Quote marks
) ;Close Strcat
) ;Close Command
(Princ)
) ;Close Defun on C:EASD
The original actually works fine. Apparently one can't store a path string in a variable from the command string?
Can anyone set me straight on this?
And yes, the folder is there - lisp just stops processing at the c: in the pathname.
Solved! Go to Solution.
Solved by scot-65. Go to Solution.
Here's a trick i used when i was faced with the same predicament
include the folder TGW is within the SFSP (support file search path)
^C^C(startapp (strcat "explorer " (findfile "TGW")))
HTH
Thanks. That works cleanly where there is one folder with that name on a drive. Unfortunately, being a developer, I have several different backup folders which this method finds. Additionally, two of the four folders that I need are on network drives and have the same name, so this just won't work in this case. However - it really works nicely if you are looking locally for a completely unique folder. The method I posted usually opens two or sometimes three copies of the exact same folder on top of each other for some weird reason. I have taken to hard-pathing each of the four folders in separate lisp routines - not bug-free, elegant or efficient, but it does work.
Again, thanks for sharring that nice method!
If you have a specific folder just put it in:
(startapp "explorer" "c:\\")
Thanks for the idea Doug, but that doesn't work from a command string like this. Just like my code example above, the buck stops at the slashes when running code from a tool on a palette...
I can't seem to find a way to sucessfully place a path as a variable into this interface, but I think the difference is negligible to doing it the following way instead, since the code string is so short. I just placed this in my ACADDOC.LSP..
(defun C:TGW-DEV-C () (startapp "explorer" "c:\\CAD\\TGW"))
and called ^C^CTGW-DEV-C from the tool to execute. I can create this 4x with differing defun names and differing paths to do it just the same. I was just trying to do it smarter with a variable and one program.
@rapidcad wrote:....none of my code will allow me to set a path through lisp directly on the tool palette.
....
I am trying to do the following now:
^C^C(setq DIR_PATH "C:\\CAD\\TGW")EASD
I get the following at the comand line:
(setq DIR_PATH "C:
....
Just a shot in the dark [I haven't experimented with it], but I wonder whether the alternative path style format, using single forward slashes instead of double back slashes, might make any difference.
Yeah Kent, I thought about that too before I posted. I turned that stone over too. the following line doesn't hang, but it doesn't make it's intended target either..
^c^c(startapp "explorer" "c:/CAD")
Instead it opens "myDocuments" folder. It does that no matter which folder I point it to.
@rapidcad wrote:I can't seem to find a way to sucessfully place a path as a variable into this interface, but I think the difference is negligible to doing it the following way instead, since the code string is so short. I just placed this in my ACADDOC.LSP..
(defun C:TGW-DEV-C () (startapp "explorer" "c:\\CAD\\TGW"))
and called ^C^CTGW-DEV-C from the tool to execute. I can create this 4x with differing defun names and differing paths to do it just the same. I was just trying to do it smarter with a variable and one program.
Try this perhaps?
(defun TGW (path / ) (startapp "explorer" path) ) ;notice there is no "c:XXX"
Then, in your macro: ^C^C(TGW "your\\path\\here");
But you say in your first paragraph that this does not work?
Then try this:
(defun TGW (flag / )
(cond
( (= flag 1) (startapp "explorer" "your\\first\\path") )
( (= flag 2) (startapp "explorer" "your\\second\\path") )
(T (startapp "explorer" "your\\third\\path") )
);cond
);TGW
Macro: ^C^C(TGW 1);
[untested]
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
@rapidcad wrote:Thanks. That works cleanly where there is one folder with that name on a drive........
Again, thanks for sharring that nice method!
You are welcome.
@rapidcad wrote:............ but I think the difference is negligible to doing it the following way instead, since the code string is so short. I just placed this in my ACADDOC.LSP..
I would have done the same in this case rapdicad. 🙂
Are these folders varies per user/loginname?
Thanks Scott. I had a look at your post this morning and with a little tweaking I was able to put together the following which works cleaner and doesn't seem to open unintended multiple instances of Explorer like other attempts that succeeded sometimes did. Also, your solution is just one defun so maybe the data footprint is a touch better?
;;;tgwfolder by Scott-65 from Autodesk discussion forums 10-22-12 (tweets by RapidCAD)
(defun TGWfolder (flag / )
(cond
( (= flag 1) (startapp "explorer" "c:\\blah\\blah_one)
( (= flag 2) (startapp "explorer" "c:\\blah\\blah_two") )
( (= flag 3) (startapp "explorer" "F:\\blah\\blah_three") )
( (= flag 4) (startapp "explorer" "G:\\blah\\blah_four") )
(T (startapp "explorer" "c:\\blah\\blah_one") )
);cond
)
;;;Macro: ^C^C(TGWfolder 1);
Thanks again- seems like a good solution.
Ron
Thanks again, Scott's code seems to work well for me. And the program was just for me, my network login. I am opening two local folders and two network folders. I really like what we're doing now. I really appreciate the contributions you made also, they help anyone who reads this post examine the options of different strategies.
Ron
@rapidcad wrote:Thanks again, Scott's code seems to work well for me. And the program was just for me, my network login. I am opening two local folders and two network folders. I really like what we're doing now. I really appreciate the contributions you made also, they help anyone who reads this post examine the options of different strategies.
Ron
if the folder is not found due to some mysterious reasons, like network is down or the folder does not exist.
(defun TGWfolder (flag / x) (setq x (assoc flag '((1 "c:\\blah\\blah_one") (2 "c:\\blah\\blah_two") (3 "F:\\blah\\blah_three") (4 "G:\\blah\\blah_four") ) ) ) (startapp "explorer" (if (and x (findfile (cadr x))) (cadr x) (progn (princ "\nFolder Not Found: Launching Explorer at drawing current folder" ) (getvar 'Dwgprefix);<--- or any default folder ) ) ) (princ) )
and in conjunction with the code above ,as in case the mapped network drive letter is different.
this will give you the network drive letter and network name
(defun _NetDrive (/ WscrptO Driveletter NDrive) (setq WscrptO (vlax-create-object "WScript.Network") Driveletter (vlax-invoke WscrptO 'EnumNetworkDrives) ) (repeat (setq i (vla-get-length Driveletter)) (setq NDrive (cons (vla-Item Driveletter (setq i (1- i))) NDrive ) ) ) (vlax-release-object WscrptO) NDrive )
and use the result from the code above to supply the correct drive letter
( _NetDrive)
(("T:" "\\\\Server")("W" "\\\\Otherserver"))
....
(setq net ( _NetDrive))
(setq x (assoc flag (list '(1 "c:\\blah\\blah_one") '(2 "c:\\blah\\blah_two") (cons 3 (strcat (caar net) "\\blah\\blah_three")) (cons 4 (strcat (caadr net) "\\blah\\blah_four")) ) ) )
......
HTH