I’d like a tip on how to clean this up and reduce the redundant lines of code. I’ll need about 10 similar task (as per defun), but only the layer names change a bit. Having some trouble just making a defun c: just do the unique items and not having to repeat redundant items like (getvar "cvport). Thanks (defun c:trial3 () (if (<= (getvar "cvport") 1) (alert "You must place the pointer/crosshair in a viewport to run this function" ) ) (if (= (getvar "tilemode") 1) (alert "You must be in a LAYOUT to run this function") ) (if (and (>= (getvar "cvport") 2) (= (getvar "tilemode") 0)) (progn (command "layer" "on" "*trial3*" "t" "*trial3*" "") (command "vplayer" "f" "fn-*" "" "f" "rm-*" "" "t" "*trial3*" "" "") (princ) ) ) ) (defun c:trial4 () (if (<= (getvar "cvport") 1) (alert "You must place the pointer/crosshair in a viewport to run this function" ) ) (if (= (getvar "tilemode") 1) (alert "You must be in a LAYOUT to run this function") ) (if (and (>= (getvar "cvport") 2) (= (getvar "tilemode") 0)) (progn (command "layer" "on" "*trial4*" "t" "*trial4*" "") (command "vplayer" "f" "fn-*" "" "f" "rm-*" "" "t" "*trial4*" "" "") (princ) ) ) )
Hi mnelson Something like this: Code: (defun c:trial1 () (Trial 1)) (defun c:trial2 () (Trial 2)) (defun c:trial3 () (Trial 3)) (defun c:trial4 () (Trial 4)) ;---------------------------------------------------------------- (defun Trial (Num / LayNme) (cond ((<= (getvar "cvport") 1) (alert (strcat "You must place the pointer/crosshair " "in a viewport to run this function." ) ) ) ((= (getvar "tilemode") 1) (alert "You must be in a LAYOUT to run this function.") ) (T (setq LayNme (strcat "*trial" (itoa Num) "*")) (command "_.layer" "_on" LayNme "_t" LayNme "" "_.vplayer" "_f" "fn-*,rm-*" "" "_t" LayNme "" "" ) ) ) (princ) ) Cheers