mrharris78 Posted December 6, 2012 Posted December 6, 2012 (if (getvar 'dwgname) "C101") (progn (c:tb1) (if (getvar 'dwgname) "C102") (progn (c:tb2) There is something missing above; I am trying to achieve to the following... IF the open drawing has name is "C101" then run this C:TB1....Else...... next IF the open drawing has name is "C102" then do this C:TB2....Else...... next IF the open drawing has name is "C103" then do this C:TB3....Else...... Do I need a LOOP??? Any hints/advice? Cheers, H Quote
paulmcz Posted December 6, 2012 Posted December 6, 2012 (cond ((= (getvar "dwgname") "c101")(c:TB1)) ((= (getvar "dwgname") "c102")(c:TB2)) ((= (getvar "dwgname") "c103")(c:TB3)) ) I'd use "cond" for this. Quote
BlackBox Posted December 6, 2012 Posted December 6, 2012 (edited) (cond ((= (getvar "dwgname") "c101")(c:TB1)) ((= (getvar "dwgname") "c102")(c:TB2)) ((= (getvar "dwgname") "c103")(c:TB3)) ) I'd use "cond" for this. While I agree that COND is well suited for this task, I'd simplify further: (vl-load-com) (defun c:FOO (/ dwgName) (cond ((vl-string-search "C101" (setq dwgName (strcase (getvar 'dwgname)))) (c:TB1) ) ((vl-string-search "C102" dwgName ) (c:TB2) ) ((vl-string-search "C103" dwgName ) (c:TB3) ) (T (prompt "\n** Drawing name does not match ** ")) ) (princ) ) ** Note - It's more efficient to store the DwgName to a variable the first time, than to query the system variable multiple times. Edited December 6, 2012 by BlackBox Changed = to vl-string-search Quote
mrharris78 Posted December 6, 2012 Author Posted December 6, 2012 Cheers guys, that's perfect. It seems to require the .dwg extension in the dwgname but that aside all good. Thank you for your help. H Quote
Lee Mac Posted December 6, 2012 Posted December 6, 2012 It seems to require the .dwg extension in the dwgname but that aside all good. If you didn't want to include the file extension in the test expressions for the cond function: (setq dwg (strcase (cadr (fnsplitl (getvar 'dwgname))))) (cond ( (= dwg "C101") (c:tb1)) ( (= dwg "C102") (c:tb2)) ( (= dwg "C103") (c:tb3)) ) Though, since "C101", "C102" etc are string literals, it would be more efficient to include the extension to avoid manipulation of the drawing filename. To demonstrate another method: (eval (cdr (assoc (strcase (cadr (fnsplitl (getvar 'dwgname)))) '( ("C101" c:tb1) ("C102" c:tb2) ("C103" c:tb3) ) ) ) ) Quote
BlackBox Posted December 6, 2012 Posted December 6, 2012 Forgetting that DwgName includes the .DWG extension (Oops), I've updated my previous post here to use vl-String-Search instead. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.