Kablamtron Posted December 9, 2008 Posted December 9, 2008 Hi all, I'm trying to get the autolisp command getfiled to go to the last folder it saved a file in when I run the lisp again. I have the default directory setup but I've been filddling around with how to get it to go back to the directory it was in when I last ran the autolisp code. (setq file (open (getfiled "specify output file" "C:/data08/" "xyz" 1) "w")) Basically thats what I'm using right now all it does it go to C:\data08\ I'm really confused is there a way to get a variable to save the last directory the command saved a file in, then call the variable when the autolisp is run again? Or is there some easier way to do it? Thanks for reading, Kablam Quote
hendie Posted December 9, 2008 Posted December 9, 2008 create a global variable for the path and substitute that instead of "C:/data08/" Quote
Kablamtron Posted January 19, 2009 Author Posted January 19, 2009 Thanks hendie, I'm trying to get that to work for some reason the getfiled doesn't like the C:\\data08\\ it will only work if I use c:\data08\. Is there some way to get the getfiled command to work with two \'s or can I convert the two \'s in to a single slash? Quote
Lee Mac Posted January 19, 2009 Posted January 19, 2009 I suppose you could store the variable using a double-double backslash: C:\\\\data08\\\\ not sure if that would work or not... Quote
Kablamtron Posted January 19, 2009 Author Posted January 19, 2009 I'll try to explain it well Getfiled can't read c:\\Data08\\ it gives me this error ; error: bad function: "C:\\Data08\\" Getfiled can read c:\Data08\ Autolisp automatically converts all \ to \\ I'm trying to use the vl-string-subst command to change the \\ to \ its not working atm but I'll keep at it. thanks for your help in advance guys this is confusing to me Quote
Kablamtron Posted January 19, 2009 Author Posted January 19, 2009 OKAY so I got it to work but have no clue why (setq file (open (getfiled "specify output file" path1 "xyz" 1) "w")) This one doesn't work! (setq file (open (getfiled "specify output file" path1 "xyz" 17) "w")) this one does I added the 16 (bit 4) If this bit is set, or if the default argument ends with a path delimiter, the argument is interpreted as a path name only. The getfiled function assumes that there is no default file name. It displays the path in the Look in: line and leaves the File name box blank. Dunno why that got it to work but it did lol man I'm terrible at this stuff thanks for your help everyone Quote
jammie Posted January 19, 2009 Posted January 19, 2009 Maybe this could be of some help also It will remember the last search path used ;Date : 19:11 19/01/2009 ;;Add to start of routine ;;Load active x support (vl-load-com) ;;Set the default directory for the first time the routine is loaded (or dir (setq dir "C:/data08/")) ;;"C:/data08/" can be changed to any path as a default ;;Verify that the directory is a valid one otherwise set it to the C drive (or (vl-file-directory-p dir)(setq dir "C:/")) (setq fname(getfiled "specify output file" dir "xyz" 1)) ;(setq file (open fname "w")) ;(close file) ;;Add to end of routine ;;Store the path for the next time the routine is run (setq dir (vl-filename-directory fname)) I am afraid I am unsure why getfiled was having trouble reading the path though.. -Jammie Quote
jammie Posted January 19, 2009 Posted January 19, 2009 Is there a possibility that the variable path1 a path with a filename? eg. C:/data08/survey.xyz Adding a 16 (bit 4) to getfiled seems to strip the filename and search for the path only. The error could be caused by passing the path and filename through getfiled with the flag set to 1 Quote
Kablamtron Posted January 20, 2009 Author Posted January 20, 2009 humm, thanks for the help jammie I will see if I can use your code it is a lot cleaner than mine, hah! and it has that nice remembering the path feature. For the path I don't believe it would include a filename. I manually enter the path in the command prompt it could have something to do with that. It could be that it strips the final \\ from the path its possible that is the problem. without 16 bit e.g. C:/data08/ with 16 bit e.g. C:/data08 I'm just guessing at why it works I have no real idea Quote
jammie Posted January 20, 2009 Posted January 20, 2009 Your welcome Kablamtron, Glad to be of some help. It could possibly be with how the string is formatted before passing it through the GETFILED and as you suggest it is adjusted when the flag is set I will see if I can use your code it is a lot cleaner than mine, hah! Thanks, I am sure your code is fine as well! I find seeing how other people write their code a huge help. This site really is a brilliant resource Good Point Jammie, and nice code. Cheers for that Lee Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.