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

Dynamic directories

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
DanielLench_
359 Views, 6 Replies

Dynamic directories

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.

 

6 REPLIES 6
Message 2 of 7
DanielLench_
in reply to: DanielLench_

@paullimapa, Got any ideas?

Message 3 of 7
paullimapa
in reply to: DanielLench_

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
Message 4 of 7
DanielLench_
in reply to: paullimapa

Thanks...

Message 5 of 7
paullimapa
in reply to: DanielLench_

You’re welcome…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 6 of 7
DanielLench_
in reply to: paullimapa

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!

 

Message 7 of 7
paullimapa
in reply to: DanielLench_

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

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report