jonathann3891 Posted March 8, 2019 Posted March 8, 2019 I've been tinkering with this lisp all week and I feel its almost complete. The only thing left that I want to add is to alert you if you try to run the command in paper space. I'm not sure if I should use a "IF" statement or "COND" statement. I've messed around with both but couldn't get it to work right. I was trying to use this "IF" statement (if (= 1 (getvar 'tilemode) Which is best for my situation and how do I implement it? (defun c:3DS (/ sel) (initget "3Dsection Restore Help") (if (null (setq sel (getkword (strcat "\nSelect Option [Restore View] <3Dsection> :")))) (setq sel "3Dsection")) (cond ((= sel "3Dsection") (3Dsection)) ((= sel "Restore") (Restore)) ) ) ; --------------------------------------------------------------------------------------------------------- (defun 3Dsection (/ ) (if (= 1 (getvar 'tilemode)) (setq ocmdecho (getvar 'cmdecho) oexpert (getvar 'expert) oregenmode (getvar 'regenmode)) (setvar "cmdecho" 0) (setvar "expert" 5) (command "-view" "s" "temp") ;;; save view "temp" (command "ucs" "s" "temp") ;;;; saves ucs to "temp" (setq pt1 (getpoint "\nCutline pt1: ")) (setq pt2 (getpoint pt1 "\nCutline pt2: ")) (setq pt1 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2))) (setq pt2 (getpoint pt1 "\nSection depth: ")) (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0)) (command "ucs" "w") (setvar "regenmode" 1) (command "dview" "" "po" pt2 pt1 "cl" "f" (distance pt2 pt1) "cl" "b" 0 "") ;;;; move ucs origin to middle of section cut line & sets to view ;;; this causes grips to be actinve in dview box because ucs origin is in box (command "ucs" "or" pt2) (command "ucs" "v") ;;; by passed next line when added setting ucs to origin. ;;; (command "ucs" "r" "tmp") ;;;; restores ucs to "tmp" (setvar 'cmdecho ocmdecho) (setvar 'expert oexpert) (setvar 'regenmode oregenmode) (princ) ) ; --------------------------------------------------------------------------------------------------------- (defun restore () (if (cdr (assoc 2 (tblsearch "view" "temp"))) (progn (command "view" "r" "temp") (command "view" "d" "temp") (command "ucs" "d" "temp") ) (prompt "\nView not found!")) (princ) ) ; --------------------------------------------------------------------------------------------------------- Quote
Lee Mac Posted March 8, 2019 Posted March 8, 2019 (edited) If you wish to use an if statement, since you will be evaluating multiple expressions when the test expression is validated, you will need to enclose the expressions constituting your 'then' argument within a progn expression, so that this single expression may be supplied as a single argument to the if function, e.g.: (if (= 1 (getvar 'tilemode)) (progn ;; multiple expressions ) (princ "\nCommand unavailable in Paperspace.") ) Notice that progn was not required for the 'else' argument, since only a single (princ) expression is being evaluated. Alternatively, since each cond condition accepts multiple arguments, a progn expression is not required, e.g.: (cond ( (= 1 (getvar 'tilemode)) ;; multiple expressions ) ( (princ "\nCommand not available in Paperspace.")) ) Edited March 8, 2019 by Lee Mac Quote
jonathann3891 Posted March 8, 2019 Author Posted March 8, 2019 Which is best for this particular situation? Quote
Lee Mac Posted March 8, 2019 Posted March 8, 2019 (edited) 2 minutes ago, jonathann3891 said: Which is best for this particular situation? Both will achieve the desired result with negligible performance difference, and so the decision could be driven by the resulting readability of the code. In this particular case I'd be inclined to suggest an if statement given that there are only two outcomes: the TILEMODE system variable is either equal to 1 or it isn't. Edited March 8, 2019 by Lee Mac Quote
ronjonp Posted March 8, 2019 Posted March 8, 2019 You could also do something like this: (cond ((= (getvar 'cvport) 1) (alert "Code does not work in paperspace! Here we come modelspace! :)") (setvar 'tilemode 1) ) ) 2 Quote
dlanorh Posted March 8, 2019 Posted March 8, 2019 1 hour ago, ronjonp said: You could also do something like this: (cond ((= (getvar 'cvport) 1) (alert "Code does not work in paperspace! Here we come modelspace! :)") (setvar 'tilemode 1) ) ) Well it made me chuckle 1 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.