I have a very simple lisp that toggles "osoptions" between 0 & 3 (basically for osnaps to ignore or snap to hatches).
It works just fine, but what I can not figire out is how to get the lisp to check the ending status of the vairable and "princ" a text string based on it's status...
You can see my attempt below (I've tried several options - this was my last & what I thougth was my best attempt)
(defun c:hs() (setvar "osoptions" (if (eq 0 (getvar "osoptions")) 3 0) ) (setq oso (getvar "osptions")) (cond ((= oso 0)(Princ "Object Snaps are set to ignore hatches")) ((= oso 3)(Princ "Object Snaps are set to snap to hatches")) ) )
Thanks,
Chris
@cchiles wrote:
...
It works just fine, but what I can not figire out is how to get the lisp to check the ending status of the vairable and "princ" a text string based on it's status...
...
(setq oso (getvar "osoptions"))
Your code
(defun c:hs( / oso) (setvar "osoptions" (if (eq 0 (getvar "osoptions")) 3 0) ) (setq oso (getvar "osoptions")) (cond ((= oso 0)(Princ "\nObject Snaps are set to ignore hatches")) ((= oso 3)(Princ "\nObject Snaps are set to snap to hatches")) ) (princ) )
HTH
Henrique
@cchiles wrote:
I have a very simple lisp that toggles "osoptions" between 0 & 3 (basically for osnaps to ignore or snap to hatches).
It works just fine, but what I can not figire out is how to get the lisp to check the ending status of the vairable and "princ" a text string based on it's status...
.... (setq oso (getvar "osptions")) ........
Could it be the omission of one of the o's in one instance of "osoptions"?
....
(setq oso (getvar "osoptions"))
....
I'm not at my newer-AutoCAD location right now where I can check, but are there possible values other than 0 and 3? If not, you can simplify that a little, without needing to test what the current value is:
(setvar 'osoptions (- 3 (getvar 'osoptions)))
And you can put the prompt [that's what you're really doing] function and most of the text content in there once, with just the variable portion differentiated, eliminating the need for the oso variable:
(prompt
(strcat
"\nObject Snaps are set to "
(if (= (getvar 'osoptions) 0) "ignore" "snap to")
" hatches."
); strcat
); prompt
Kent1Cooper wrote:
...
And you can put the prompt [that's what you're really doing] function and most of the text content in there once, with just the variable portion differentiated, eliminating the need for the oso variable:
(prompt (strcat "\nObject Snaps are set to " (if (= (getvar 'osoptions) 0) "ignore" "snap to") " hatches." ); strcat ); prompt
...
Nicely done!
Chris,
using Kent1Cooper's approach, may simply be
(defun c:hs nil (prompt (strcat "\nObject Snaps are set to " (if (= (getvar 'osoptions) 0) (progn (setvar "osoptions" 3) "ignore") (progn (setvar "osoptions" 0) "snap to") ) " hatches." );; strcat );; prompt (princ) )
Henrique
@hmsilva wrote:
@ Kent1Cooper wrote:
...
And you can put the prompt [that's what you're really doing] function and most of the text content in there once, with just the variable portion differentiated, eliminating the need for the oso variable:...
Nicely done!
Chris,
using Kent1Cooper's approach, may simply be
.... "\nObject Snaps are set to " (if (= (getvar 'osoptions) 0) (progn (setvar "osoptions" 3) "ignore") (progn (setvar "osoptions" 0) "snap to") ) " hatches." ....
Henrique
Thank you! It can be collapsed even a little further, combining both earlier suggestions:
(defun C:HS ()
(prompt
(strcat
"\nObject Snaps are set to "
(if (= (setvar 'osoptions (- 3 (getvar 'osoptions))) 0) "ignore" "snap to")
" hatches."
)
)
(princ)
)
@Kent1Cooper wrote:
...
Thank you! It can be collapsed even a little further, combining both earlier suggestions:
(defun C:HS ()
(prompt
(strcat
"\nObject Snaps are set to "
(if (= (setvar 'osoptions (- 3 (getvar 'osoptions))) 0) "ignore" "snap to")
" hatches."
)
)
(princ)
)
You're welcome!
I would not use the
(= (setvar 'osoptions (- 3 (getvar 'osoptions))) 0)
because there are other possible values than 0 and 3...
Henrique
Since the OSOPTIONS system variable is bit-coded, I would recommend the following:
(defun c:hs nil (if (= 1 (logand 1 (setvar 'osoptions (boole 6 1 (getvar 'osoptions))))) (princ "\nHatches ignored.") (princ "\nHatches snapped.") ) (princ) )
@hmsilva wrote:
....I would not use the
(= (setvar 'osoptions (- 3 (getvar 'osoptions))) 0)
because there are other possible values than 0 and 3...
I kind of figured there might be [that's why I asked], because of the values in question being 0 and 3, rather than 0 and 1. Now I don't need to look into it in a newer version.
Since a number of options settings are bit-coded, I'd recommend a pair of handler functions to convert an int to a list of (something), and a list of (something) to an integer. For example, the former could take the system variable value (int) and a list of dotted pairs (string . int_flag), and return a list of appropriate dotted pairs that are representative of the bits that are set.
Hey Thanks everyone.
I'm very very novice at this (as you noticed I'm sure) lots of good explanatioins & ideas!