Zykl0 Posted November 5, 2008 Posted November 5, 2008 i'm trying to make a routine (my first one) that switch 2 layer state everytime i call the function. (defun c:layswitch (/ layvar) (setvar "layvar" 1) (if (=(getvar "layvar") 1) (command "layer" "A" "R" "T1" "" "") (setvar "layvar" 0) ) ;if (if (=(getvar "layvar") 0) (command "layer" "A" "R" "T2" "" "") (setvar "layvar" 1) ) ;if );defun Can you tell me whats wrong with the code? thank you. Quote
neekcotrack Posted November 5, 2008 Posted November 5, 2008 (defun c:layswitch (/ layvar) (setvar "layvar" 1) (if (=(getvar "layvar") 1) (command "layer" "A" "R" "T1" "") (setvar "layvar" 0) ) ;if (if (=(getvar "layvar") 0) (command "layer" "A" "R" "T2" "") (setvar "layvar" 1) ) ;if (princ) );defun Just looking real quick this is what I seen, plus what is LAYVAR? Quote
Zykl0 Posted November 5, 2008 Author Posted November 5, 2008 Humm a variable i created? for switching between layerstate T1 and T2 everytime i call the function is it good? Edit: this is definetly not working something to do with layvar... i read somewhere i needed to call my variable between defun () bracket. but i guess i misunderstood Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 Humm a variable i created? for switching between layerstate T1 and T2 everytime i call the function is it good? You should probably use either use "setenv" for setting a system environment variable or just the usual "setq" for setting a local variable. Quote
Zykl0 Posted November 5, 2008 Author Posted November 5, 2008 ok whats wrong with the syntax please? (defun c:layswitch () (setq "layvar" 1) (if ("layvar" = 1) (command "layer" "A" "R" "T1" "") (setq "layvar" 0) ) ;if (if ("layvar" = 0) (command "layer" "A" "R" "T2" "") (setq "layvar" 1) ) ;if (princ) );defun Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 When using the "setq", don't use quote marks around your variable name, and also, to check equality use: (= xxxx yyy) not: ("xxxx" = yyy) (defun c:layswitch (/ layvar) (setq layvar 1) (if (= layvar 1) (command "layer" "A" "R" "T1" "") (setq layvar 0) ) ;if (if (= layvar 0) (command "layer" "A" "R" "T2" "") (setq layvar 1) ) ;if (princ) );defun Quote
Zykl0 Posted November 5, 2008 Author Posted November 5, 2008 excellent thank you this part is working, now everytime i run the function it set only my layer state to T1 (never T2) i guess its because of the line 2 the variable is always set to 1. any idea? Quote
flowerrobot Posted November 5, 2008 Posted November 5, 2008 now everytime i run the function it set only my layer state to T1 (never T2) i guess its because of the line 2 the variable is always set to 1. any idea? (setq "layvar" 1) (if ("layvar" = 1) correct,That is your problem Your setting layvar to 1,so its always going to be 1 Im not sure not sure what you are trying to do, (coffee hasnt kicked in yet) so i carnt help you to much, sorry, but are you trying to switch layers? so like if current layer is t1 go to t2 and if current layer is t2 go to t1? Regards Quote
Zykl0 Posted November 5, 2008 Author Posted November 5, 2008 so like if current layer is t1 go to t2 and if current layer is t2 go to t1? yes this is what i'm trying to do Quote
ASMI Posted November 5, 2008 Posted November 5, 2008 Boolean in LISP is nil (false) and T (true) not 0 and 1. Variable 'layvar' in this case must be global. In real LISP: (defun c:layswitch() (if layvar (progn (command "layer" "A" "R" "T1" "") (setq layvar nil) ); end progn (progn (command "layer" "A" "R" "T2" "") (setq layvar T) ); end progn ); end if (princ) ); end of c:layswitch Quote
Zykl0 Posted November 5, 2008 Author Posted November 5, 2008 working perfectly! thank you all but i have no clue what is progn. the progn tab in the help file is in chinese to me Quote
flowerrobot Posted November 5, 2008 Posted November 5, 2008 i would of (defun c:layerswitch () [b](setq mrpeepee (getvar "_.clayer))[/b] (if (= mrpeepee t1) (command "_.clayer" "T2")) (if (= mrpeepee t2) (command "_.clayer" "T1")) ) the bold is not correct im pritty sure, i just carnt find the varible for it. plz advise if you find it. ps, i would also chuck in a cmdecho 0 & 1 Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 (defun c:layerswitch (/ mrpeepee) (setvar "cmdecho" 0) (setq mrpeepee (getvar "clayer")) (if (= mrpeepee "t1") (command "_.clayer" "T2")) (if (= mrpeepee "t2") (command "_.clayer" "T1")) (setvar "cmdecho" 1) (princ) ) loving the "mrpeepee" -- very original Quote
flowerrobot Posted November 5, 2008 Posted November 5, 2008 o.0 i got the varible corret, yay for me , i took a guess at that, thanks for cleaning that code up for me. 1 questions tho why did ya put mrpeepee in the defun line "(/mrpeepee)" you if you were naming your child would you call him "babie" or "b' or "ba" no you would give him a name. same with functions (if you can be bothered that is) Quote
Zykl0 Posted November 6, 2008 Author Posted November 6, 2008 haha very original i like it i should call my variable starting with Mr (spaceball) i also would like to know why we need to put the variable in the defun function what happend if not? Quote
Least Posted November 6, 2008 Posted November 6, 2008 It defines it as a local variable. If it wasn't defined as local, then it could cause conflicts with other lisps which may happen to use the same variable name. Quote
Lee Mac Posted November 6, 2008 Posted November 6, 2008 See here for more info: http://www.cadtutor.net/forum/showthread.php?t=28861 (See post #6) 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.