Dynamic directories

Dynamic directories

DanielLench_
Advocate Advocate
2,573 Views
6 Replies
Message 1 of 7

Dynamic directories

DanielLench_
Advocate
Advocate

I want to set a variable ($SupportDir) that is called from a bunch of other lisps using vl-propogate. I want that variable to be conditional for when a user has synced with ACC the first time (we are rolling it out to the company shortly) or if they are on the VPN or using a local. This is in the acad.lsp and I input the $dir# above this block. Can someone please sanity-check this? Thanks!

 

(setq $Dir1 "ACC\Dir") ; this one does not exist for this example

(setq $Dir2 "VPN\Dir"); this one does exist

(setq $Dir3 "Local\Dir"); this one exists but we want dir2 to be used because of preference like the user is connected to the VPN

 

(setq $SupportDir
(cond
(vl-file-directory-p $Dir1 $Dir1)
(vl-file-directory-p $Dir2 $Dir2)
(vl-file-directory-p $Dir3 $Dir3)
(t (princ "Couldn't set Support directory-p"))
(princ $SupportDir)
)
)

 

my expectation is that $Dir2 will be set as the $SupportDir which is used throughout the ACAD session.

 

0 Likes
Accepted solutions (1)
2,574 Views
6 Replies
Replies (6)
Message 2 of 7

DanielLench_
Advocate
Advocate

@paullimapa, Got any ideas?

0 Likes
Message 3 of 7

paullimapa
Mentor
Mentor
Accepted solution

Nice start and here are my thoughts:

In order for code to verify existence of directory, you'll have to provide complete path like:
c:\\ACC\\Dir

Note: AutoLISP requires double backslashes

You'll have to follow correct syntax for:

vl-file-directory-p

cond

So your code may end up something like:

(setq $Dir1 "C:\\ACC\\Dir") ; this one does not exist for this example
(setq $Dir2 "C:\\VPN\\Dir"); this one does exist
(setq $Dir3 "C:\\Local\\Dir"); this one exists but we want dir2 to be used because of preference like the user is connected to the VPN

 (cond
  ((vl-file-directory-p $Dir1) (setq $SupportDir $Dir1))
  ((vl-file-directory-p $Dir2) (setq $SupportDir $Dir2))
  ((vl-file-directory-p $Dir3) (setq $SupportDir $Dir3))
  (t (princ "Couldn't set Support directory-p"))
 )
 (princ $SupportDir)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 7

DanielLench_
Advocate
Advocate

Thanks...

0 Likes
Message 5 of 7

paullimapa
Mentor
Mentor

You’re welcome…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 7

DanielLench_
Advocate
Advocate

Thanks, @paullimapa,

I already have the directories declared properly, the given ones are generic and just for the example. 

Looks like I was just missing the fact that the setq needs to be wrapped inside of the conditional test? So given that directories 2 and 3 exist, the code you provided will stop at dir2, which is the desired result?

 

I'm still wrapping my head around the cond function and don't really want to nest a bunch of if statements. 

 

Thanks brother!

 

0 Likes
Message 7 of 7

paullimapa
Mentor
Mentor

Just continue to do trial and error on your own at AutoCADs command prompt. You can copy and paste the entire cond statements and see what it returns


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos