Jump to content

Recommended Posts

Posted

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.

Posted

(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?

Posted

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

Posted
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.

Posted

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

Posted

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

Posted

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? :)

Posted

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

Posted

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 :x

Posted

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 

Posted

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

Posted

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

Posted

(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 :P

Posted

o.0 i got the varible corret, yay for me :D, 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)

Posted

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?

Posted

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.

Posted

See here for more info:

http://www.cadtutor.net/forum/showthread.php?t=28861

 

(See post #6)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...