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.
Solved! Go to Solution.
Solved by paullimapa. Go to 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:
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)
You’re welcome…cheers!!!
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!
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
Can't find what you're looking for? Ask the community or share your knowledge.