Hello all,
We are changing the way we use AutoCAD Electrical, and there is a complication...
All of our electrical databases will have the same locations across many systems after the update.
The problem is, there is no way to make our new database location take precidence over the default location unless the default is deleted.
I can go to each system and delete the default location, but this is unrealistic for us.
The location is something to the effect of "C:\Users\'USERNAME'\Documents\ blah blah blah...".
My question is this...
How do I make a LISP navigate to the current user's default database location, and delete that folder, or file, so the new database location will be the new "default".
--Thanks in Advanced
Thomas Walls
CADMASTER TECHNOLOGIES, LLC
www.cadmastertech.com
Solved! Go to Solution.
Solved by BlackBox_. Go to Solution.
Not sure where "Environment variable" figures anywhere into this...
If you need to delete a file or folder, BAT file may be better. You can script it to run when users start or log in, or "deploy it" through SCCM or other tools. You can even hyperlink it in a global email if you want simple as dirt.
Better yet, work on pulling local data out of the ...\USERS\... path and into something *you* create, so the user name is never part of the picture.
This is along the lines of what I am looking for...
(setq FSO (vlax-create-object "Scripting.FileSystemObject")) (vlax-invoke FSO "DeleteFolder" "C:\\Users\\%USERNAME%\\Documents\\Acade 2013\\AeData\\Catalogs" :vlax-true) (vlax-release-object FSO)
The only issue with this is when I use the %USERNAME% variable, I get an error...
; error: Exception occurred
If I change the %USERNAME% back to a "valid" username, like the name of my folder, it works fine.
Am I missing something, or do LISPs not work with Windows environment variables?
I agree with dgorsman that a BAT file would take care of it nicely.
If you must use lisp here is a function that I use
(defun getMyDocs (/ UserProfile) (setq UserProfile (getenv "userprofile")) (if (vl-string-search "Settings" UserProfile) (strcat (getenv "userprofile") (chr 92) "My Documents");;;For Windows Xp (strcat (getenv "userprofile") (chr 92) "Documents");;;For Windows 7 ) )
Windows variables do work with lisp. I usually define the variable for example
(setq user (getenv "username"))
@jayala79 wrote:Windows variables do work with lisp. I usually define the variable for example
(setq user (getenv "username"))
... And in some instances, these are also available via System Variable:
(getvar 'loginname)
"How we think determines what we do, and what we do determines what we get."
So this will suit my needs.
(setq USER (getenv "username"))
Next, if you can help me with this is...
I am unable to get this to work.
(setq PATH (strcat "C:\\User\\"(getenv "username")"\\Docuents\\Acade 2013\\AEData\\Catalogs")) (setq FSO (vlax-create-object "Scripting.FileSystemObject")) (vlax-invoke FSO "DeleteFolder" PATH :vlax-true) (vlax-release-object FSO)
Perhaps i am using the "vlax-invoke FSO" improperly?
@TomTom111 wrote:Next, if you can help me with this is...
I am unable to get this to work.
(setq PATH (strcat "C:\\User\\"(getenv "username")"\\Docuents\\Acade 2013\\AEData\\Catalogs")) (setq FSO (vlax-create-object "Scripting.FileSystemObject")) (vlax-invoke FSO "DeleteFolder" PATH :vlax-true) (vlax-release-object FSO)Perhaps i am using the "vlax-invoke FSO" improperly?
You have a typo:
\\Docuents
Though, I would recommend the following:
(defun deletefolder ( pth / fso rtn ) (if (and (setq pth (findfile pth)) (setq fso (vlax-create-object "scripting.filesystemobject")) ) (progn (setq rtn (vl-catch-all-apply 'vlax-invoke-method (list fso 'deletefolder pth :vlax-true))) (vlax-release-object fso) (not (vl-catch-all-error-p rtn)) ) ) ) (vl-load-com) (princ)
Example:
(deletefolder (strcat "C:\\User\\" (getenv "username") "\\Documents\\Acade 2013\\AEData\\Catalogs"))