Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Enviornment Variable in LISP

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
TomTom111
1691 Views, 10 Replies

Enviornment Variable in LISP

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

 

10 REPLIES 10
Message 2 of 11
dgorsman
in reply to: TomTom111

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 3 of 11
TomTom111
in reply to: dgorsman

 

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?

Message 4 of 11
matt.worland
in reply to: TomTom111

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
	)
)

 

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"
Message 5 of 11
dmfrazier
in reply to: TomTom111

There is a sysvar (saved in registry) named "mydocumentsprefix" that you might be able to use.

Message 6 of 11
jayala79
in reply to: TomTom111

Windows variables do work with lisp. I usually define the variable for example

 

(setq user (getenv "username"))

Message 7 of 11
BlackBox_
in reply to: jayala79


@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."

Message 8 of 11
TomTom111
in reply to: BlackBox_

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?

Message 9 of 11
Lee_Mac
in reply to: TomTom111


@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"))

 

Message 10 of 11
TomTom111
in reply to: Lee_Mac


@Lee_Mac wrote:


 

You have a typo:

\\Docuents


Thanks for catching that!  Smiley Embarassed
Thank you for your reply sir, I will give that a shot.

 

Message 11 of 11
Lee_Mac
in reply to: TomTom111

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost