TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Krushert on April 19, 2011, 03:22:38 PM
-
Using lisp, what do I use to find the location of MyDocuments folder?
FindFile will not work here because the users MyDocuments folders resides between the parallel universe of the server and client machine. I am being a wise flower and it long story as to why I want Autocad to find and it and not me hard coding the path into my code. One reason is that I want to see if really knows where the folder is and not it following my path blindly.
The path as seen in the options dialog is
\\cws-server\users\ted krush\my documents\
-
(getvar 'MYDOCUMENTSPREFIX)
-
Duhh! "prefix" I never thought of searching by prefix! Thanks.
-
Duhh! "prefix" I never thought of searching by prefix! Thanks.
I opened SYSVDLG and typed in *doc*. :-D
-
Doesn't answer you question but here's a peek to the "special" folders:
(defun c:test (/ n out sa sp)
(and (setq sa (vlax-create-object "WScript.Shell"))
(setq sp (vlax-get sa 'specialfolders))
(setq n -1)
(repeat (vlax-get sp 'length) (setq out (cons (vla-item sp (setq n (1+ n))) out)))
(alert (vl-prin1-to-string out))
)
)
-
Very nice, Ron.
also...
Command: (findfile ".")
"C:\\Users\\athompson\\Documents"
-
Very nice, Ron.
also...
Command: (findfile ".")
"C:\\Users\\athompson\\Documents"
:) What is (findfile ".") pointing to?
Mine prints "C:\\Program Files\\Aqua Engineering, Inc\\WatermarkID 2009"
-
Very nice, Ron.
also...
Command: (findfile ".")
"C:\\Users\\athompson\\Documents"
:) What is (findfile ".") pointing to?
Mine prints "C:\\Program Files\\Aqua Engineering, Inc\\WatermarkID 2009"
Sorry, I meant type out the question of what it returns for you. :ugly:
I stumbled across that the other day and was quite puzzled by it - works with ".." also.
-
I believe this returns the "Start in" folder specified in the shortcut used to start acad.
-
I believe this returns the "Start in" folder specified in the shortcut used to start acad.
I'm using pinned shortcuts in Win7, so that's probably why I'm receiving my documents folder. Interesting.
-
I believe this returns the "Start in" folder specified in the shortcut used to start acad.
Looks to be the case here. Thanks Jeff.
-
(findfile ".") is interesting.
This goes back to the days of DOS. Every directory (folder) contains two "files" - A single dot represents the "current" directory (folder); two dots represents the parent of the current directory (folder), i.e., the part of the path returned by single dot with the current directory chopped off. And while that is initally the "Start in" folder listed in the ACAD shortcut, some commands, such as SAVEAS, can change the current directory to whatever directory is selected for the "Save to". This can be very bothersome when some user settings are predicated on the current directory always being the Start in folder.
-
(findfile ".") is interesting.
This goes back to the days of DOS. Every directory (folder) contains two "files" - A single dot represents the "current" directory (folder); two dots represents the parent of the current directory (folder), i.e., the part of the path returned by single dot with the current directory chopped off. And while that is initally the "Start in" folder listed in the ACAD shortcut, some commands, such as SAVEAS, can change the current directory to whatever directory is selected for the "Save to". This can be very bothersome when some user settings are predicated on the current directory always being the Start in folder.
Very interesting. I never considered the days of running DOS and typing cd.. to back up one directory folder.
-
I'd probably go with the SpecialFolders object, but for more cat-skinning:
(vl-registry-read "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" "Personal")
-
What do you mean `dos days' (I sense some nostalgia). ...I still use those dots.
My entry.
(getstring "\nEnter the path to your \"My Documents\" folder: ")
:p
-
I'd probably go with the SpecialFolders object
Why, is the system variable too simple?
-
:-D Wow! you guys ran with this one. :-D
I'd probably go with the SpecialFolders object
Why, is the system variable too simple?
Not for me it isn't. It curls up very nicely inside my simple mind.
The more complex methods is for more complex minds.
:-D :-D
Thanks again guys.
-
Nostalgia? maybe.
On the other hand... there are some things you can do faster and easier in DOS. Our application includes a simple command - DOS - which opens a DOS window. If I can get a user to DOS, I can tell him/her Type this, Type that... and before you know it, we've done what needs to be done. I tell a user to open "Windows Explorer" and they almost always start "Internet Explorer"...
-
I am a comand prompt junkie (well that comes froms being a *nix user though too).
AutoCAD conversations:
"type in: sh <enter> <enter> ..."
-
Okay next question.
LOCALROOTPREFIX gives me this = "C:\\Users\\Ted Krush\\AppData\\Local\\Autodesk\\ACA 2010\\enu\\"
Is there something out there that will get me this = "C:\\Users\\Ted Krush\\AppData\\Local <=== back slashes can be present or not.
-
getenv TMP or TEMP may get you close :wink:
-
What Lee said:
(substr (getenv "Temp") 1 (vl-string-search "\\Temp" (getenv "Temp")))
-
getenv TMP or TEMP may get you close :wink:
FYI: That will abbreviate the folder names if they are too long.
eg.
Command: (getenv "Tmp")
"C:\\Users\\ATHOMP~1\\AppData\\Local\\Temp"
-
What Lee said:
(substr (getenv "Temp") 1 (vl-string-search " \\Temp"(getenv "Temp")))
Okay how did you do that? and by that I mean tell to "delete" the " \\Temp" from the string?
The vl-string-search function searches the string not deletes from my reading the help file on vl-string-search.
<sigh> I wish the help was little more dynamic when it comes to holding my hand.
-
What Lee said:
(substr (getenv "Temp") 1 (vl-string-search " \\Temp"(getenv "Temp")))
Okay how did you do that? and by that I mean tell to "delete" the " \\Temp" from the string?
The vl-string-search function searches the string not deletes from my reading the help file on vl-string-search.
<sigh> I wish the help was little more dynamic when it comes to holding my hand.
Look at the substr in the beginning of the call.
-
Look at the SUBSTR function (which does the trimming)
(vl-string-search " \\Temp"(getenv "Temp")) returns a number where the string "\\Temp" starts.
SUBSTR starts at a point in a string (in this case the beginning (1)) then stops at the beginning of "\\Temp" which was returned by the vl-string-search.
Maybe this will help you see it:
(setq string (getenv "Temp"))
;;If "\\Temp" is found in string
(if (setq p (vl-string-search "\\Temp" string))
;;Trim the string
(substr string 1 p)
;;Else return the full string
string
)
-
Ahh the search is returning numerical position of where \\Temp starts in the string.
Me gets it now. Thanks again.
-
Ahh the search is returning numerical position of where \\Temp starts in the string.
Me gets it now. Thanks again.
:) Glad to help out.
-
How do I trim the right side of a sting to certain known character with unknown characters in between.
"\\\\server\\users\\ted krush\\my documents\\Folder name varies\\ To be trimmed but folder name also varies \\"
I can not get either vl-string-right-trim or Substr functions to fit.
I am trying to slice it and dice it using this ginzo code and it not working.
(setq OldUserFolder1 (vl-filename-directory (findfile "acad.pgp")))
(setq OldUserFolder2 (vl-string-right-trim "\\" OldUserFolder1))
A little push please?
-
If I understand the question look into this:
(vl-string-position char-codestr [start-pos [from-end-p]])
Arguments
char-code
The integer representation of the character to be searched.
str
The string to be searched.
start-pos
The position to begin searching from in the string (first character is 0); 0 if omitted.
from-end-p
If T is specified for this argument, the search begins at the end of the string and continues backward to pos
-
This is where I was going with it:
(setq olduserfolder1 (vl-filename-directory (findfile "acad.pgp")))
(substr olduserfolder1 1 (vl-string-position (ascii "\\") olduserfolder1 0 t))
-
Ted you can also use something like this if you know how many folders to chop off the end. Gives you a bit more flexibility.
(defun _chop (string delimeter #2chop / n)
(setq n -1)
(while
(and (setq p (vl-string-position (ascii delimeter) string 0 t)) (< (setq n (1+ n)) #2chop))
(setq string (substr string 1 p))
)
string
)
;;Little test
(setq n 0)
(repeat 10 (alert (_chop (vl-filename-directory (findfile "acad.pgp")) "\\" (setq n (1+ n)))))
-
Thanks guys. That gives me something to chew on tomorrow while I am work.
-
Another for fun:
(defun _chop ( dir n / p )
(if (and (setq p (vl-string-position 92 (vl-string-right-trim "\\" dir) 0 t)) (< 0 n))
(_chop (substr dir 1 p) (1- n))
dir
)
)
(setq n 0) (repeat 10 (print (_chop (findfile "acad.pgp") (setq n (1+ n)))))
-
(findfile ".") is interesting.
This goes back to the days of DOS. Every directory (folder) contains two "files" - A single dot represents the "current" directory (folder); two dots represents the parent of the current directory (folder), i.e., the part of the path returned by single dot with the current directory chopped off. And while that is initally the "Start in" folder listed in the ACAD shortcut, some commands, such as SAVEAS, can change the current directory to whatever directory is selected for the "Save to". This can be very bothersome when some user settings are predicated on the current directory always being the Start in folder.
Late to the party but thought all may find this interesting.
From an old thread, not mine.
I noticed a long time a go to, that findfile behaves quite rare... here are
some of the non-document stuff I found and maybe others here already know.
(findfile "c:\\blocks\\122d\\12EBED01.DWG") ;;ok
(findfile "c:\\blocks\\122d\\") ;;wrong
(findfile "c:\\blocks\\122d\\.") ;;ok
;; find path...
(findfile "c:\\blocks\\ada\\...")
"C:\\blocks\\ada\\"
(findfile "c:\\blocks\\ada\\..")
"C:\\blocks"
;; get current directory...
(findfile "cd\\..")
"C:\\Program Files\\AutoCAD 2000i"
;; get main directory...
(findfile "c:..")
"C:\\Program Files"
;; get the root...
(findfile "\\.")
(findfile "/..")
(findfile "\\..")
"C:\\"
(findfile "\\program files\\autocad 2000i.")
"C:\\program files\\autocad 2000i"
;; get current directory...
(findfile "cd\\..")
"C:\\Program Files\\AutoCAD 2000i"
;; get main directory...
(findfile "c:..")
"C:\\Program Files"
;; get the root...
(findfile "\\.")
"C:\\"
;; for a particular folder
(if (setq path (findfile "acetutil.fas"))
(vl-filename-directory path))
"C:\\Program Files\\AutoCAD 2000i\\express"
-
Interesting CAB - thanks :-)
-
Very interesting. Thanks for sharing, Alan.
-
Very interesting. Thanks for sharing, Alan.
Like he said. Thanks CAB
-
Quite welcome. 8-)