Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add a "Princ" of a txt string based on SysVar value.

9 REPLIES 9
Reply
Message 1 of 10
cchiles
464 Views, 9 Replies

How to add a "Princ" of a txt string based on SysVar value.

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

 

Thanks in advance!
-Chris
9 REPLIES 9
Message 2 of 10
hmsilva
in reply to: cchiles


 

@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

 

EESignature

Message 3 of 10
Kent1Cooper
in reply to: cchiles


@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

Kent Cooper, AIA
Message 4 of 10
hmsilva
in reply to: cchiles

@Kent1Cooper 

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!

 

@cchiles 

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

EESignature

Message 5 of 10
Kent1Cooper
in reply to: hmsilva


@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)

)

Kent Cooper, AIA
Message 6 of 10
hmsilva
in reply to: Kent1Cooper


@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

 

EESignature

Message 7 of 10
Lee_Mac
in reply to: cchiles

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

 

Message 8 of 10
Kent1Cooper
in reply to: hmsilva


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

Kent Cooper, AIA
Message 9 of 10
dgorsman
in reply to: Lee_Mac

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 10 of 10
cchiles
in reply to: dgorsman

Hey Thanks everyone.

I'm very very novice at this (as you noticed I'm sure) lots of good explanatioins & ideas!

Thanks in advance!
-Chris

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost