Jump to content
Pugazh

Setvar 'Snapang using lisp with greater-than or equal condition

Recommended Posts

Pugazh
(defun RtoD (nbrOfRadians)
  (/ (* nbrOfRadians 180.0) pi)
)

(defun DtoR (nbrOfDegrees)
  (* (/ nbrOfDegrees 180.0) pi)
)

(if (>= (cvunit (getvar 'snapang) "radians" "degrees") 180.0)
    (setvar 'snapang (- (cvunit (getvar 'snapang) "radians" "degrees") 180.0))
)

Hi, i think this code is totally wrong please help me!

Edited by Pugazh

Share this post


Link to post
Share on other sites
Pugazh
(defun RtoD (nbrOfRadians)
  (/ (* nbrOfRadians 180.0) pi)
)

(defun DtoR (nbrOfDegrees)
  (* (/ nbrOfDegrees 180.0) pi)
)

(if (>= (cvunit (getvar 'snapang) "radians" "degrees") 180.0)
    (command "_.snapang" (- (cvunit (getvar 'snapang) "radians" "degrees") 180.0))
)

This code is working fine :) :beer:

Share this post


Link to post
Share on other sites
Lee Mac

The code could alternatively be written:

(if (<= pi (getvar 'snapang))
    (setvar 'snapang (- (getvar 'snapang) pi))
)

Or simply:

(setvar 'snapang (rem (getvar 'snapang) pi))

 

  • Thanks 2

Share this post


Link to post
Share on other sites
Pugazh

thanks @Lee Mac :beer:

 

Edited by Pugazh

Share this post


Link to post
Share on other sites
Pugazh

Hi @Lee Mac,

 

i have some doubt about snapang. please see the attached file.

 

i want as per attached image have two condition in one lisp code it's possible? (must be check the two condition at the same time)

snapang.png

Share this post


Link to post
Share on other sites
dlanorh
(if (< (/ pi 2) (getvar 'snapang) (* (/ pi 2) 3)) (setvar 'snapang (+ (getvar 'snapang) pi)))

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Lee Mac

Alternatively, without if statements:

(setvar 'snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0)))

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Pugazh

Wow !! Exactly  i needed this one :) thank you @dlanorh & @Lee Mac cheers :beer:

Share this post


Link to post
Share on other sites
Pugazh

How to combine ? one if condition :(

 

(if (< (/ pi 2) (getvar 'snapang) (* (/ pi 2) 3)) (setvar 'snapang (+ (getvar 'snapang) pi)))
(if (= (getvar 'snapang) (/ pi 2)) (setvar 'snapang (/ pi 2)))
(if (= (getvar 'snapang) (* (/ pi 2) 3)) (setvar 'snapang (/ pi 2)))

 

Share this post


Link to post
Share on other sites
tombu
(if (= (setvar 'snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0)))(* (/ pi 2) -1))(setvar 'snapang (/ pi 2)))

Now it works!

Edited by tombu
coding error
  • Thanks 1

Share this post


Link to post
Share on other sites
Pugazh
14 hours ago, tombu said:

(if (= (setvar 'snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0)))(* (/ pi 2) -1))(setvar 'snapang (/ pi 2)))

Now it works!

thank you @tombu :beer:

Share this post


Link to post
Share on other sites
Pugazh

I have another doubt!

If i set snapang any angle, it should be automatically change to as per autocad dimension text rotation. it's possible ?

Share this post


Link to post
Share on other sites
tombu

As I do Civil / Survey drawings whose plan views are all twisted in each viewport I wrote this to set selected block insert, text, mtext, & dimtext angles Horizontal. 

I've modified it for you to use the snap angle if the view isn't twisted. 

;| ;| https://forums.augi.com/showthread.php?171018-rotate-text-to-horizontal-in-viewport&p=1332928&viewfull=1#post1332928
   http://www.theswamp.org/index.php?topic=55060.msg595136#msg595136
   https://www.cadtutor.net/forum/topic/68912-setvar-snapang-using-lisp-with-greater-than-or-equal-condition/?tab=comments#comment-557172
Set block insert, text, mtext, & dimtext angle Horizontal by Tom Beauford
 (load "TextHoriz.lsp") TextHoriz
   Macro: ^P(or C:TextHoriz (load "TextHoriz.lsp"));TextHoriz
   Command line: (load "TextHoriz.lsp") TextHoriz |;
(defun c:TextHoriz (/ ss1 num cnt viewtwist snapang etype obj dimr)
  (setq ss1 (ssget '((0 . "insert,mtext,text,dimension")))
        num (sslength ss1)
        cnt 0
        viewtwist (getvar "viewtwist")
        snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0))
  )
  (if (or (= snapang (* (/ pi 2) -1)) (= snapang (* (/ pi 2) 3)))(setvar 'snapang (/ pi 2)))
  (if(/= viewtwist 0.0)
	(repeat num
	  (setq ent (ssname ss1 cnt)etype (cdr(assoc 0 (entget ent))))
	  (setq obj (vlax-ename->vla-object ent))
	  (if(= etype "DIMENSION")
		(progn
		  (setq dimr (- (vla-get-Rotation obj)viewtwist))
		  (vla-put-TextRotation obj dimr)
		)
		(vla-put-Rotation obj (- viewtwist))
	  )
	  (setq cnt (1+ cnt))
	) ; repeat
	(repeat num
	  (setq ent (ssname ss1 cnt)etype (cdr(assoc 0 (entget ent))))
	  (setq obj (vlax-ename->vla-object ent))
	  (if(= etype "DIMENSION")
		(progn
		  (setq dimr (+ (vla-get-Rotation obj)snapang))
		  (vla-put-TextRotation obj dimr)
		)
		(vla-put-Rotation obj snapang)
	  )
	  (setq cnt (1+ cnt))
	) ; repeat
;	(princ "\nNo TWist in Viewport.")
  ) ; if
  (princ)
)

 

Edited by tombu
Updated to fix both snapang 270 or -90.
  • Thanks 1

Share this post


Link to post
Share on other sites
Pugazh

Thank you @tombu!! 

  

   I think my question is wrong :(  , How to take snap angle in aligned dimensions text rotation ? if i draw dimension text automatically rotated as per snap angle.

 

i need this snap angle code with if conditions 

 

like this

(if (= (setvar 'snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0)))(* (/ pi 2) -1))(setvar 'snapang (/ pi 2)))

 

Share this post


Link to post
Share on other sites
tombu
5 minutes ago, Pugazh said:

Thank you @tombu!! 

  

   I think my question is wrong :(  , How to take snap angle in aligned dimensions text rotation ? if i draw dimension text automatically rotated as per snap angle.

 

i need this snap angle code with if conditions 

 

like this


(if (= (setvar 'snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0)))(* (/ pi 2) -1))(setvar 'snapang (/ pi 2)))

 

I modified the code for that 38 minutes ago, have you tried the updated code?

Share this post


Link to post
Share on other sites
Pugazh
    (command "_.snapang" "_non" pt1 "_non" pt2)
    (if (= (setvar 'snapang (- (rem (+ (getvar 'snapang) (/ pi 2.0)) pi) (/ pi 2.0)))(* (/ pi 2) -1))(setvar 'snapang (/ pi 2)))

@tombu , I did not change rotation.

 

I have two points, pt1 is block mid point, pt2 is block insert point.

now snapang is 270 from the pt1 & pt2. i use this code sometimes update snapangle 90 but sometimes not update :( why i know :( 

Share this post


Link to post
Share on other sites
tombu
On 10/29/2019 at 5:04 AM, Pugazh said:

How to combine ? one if condition :(

 

I've updated the code to correct snapang of either (* (/ pi 2) 3) or (* (/ pi 2) -1).

Edited by tombu
  • Thanks 1

Share this post


Link to post
Share on other sites
Lee Mac

@Pugazh Assuming I've understood what you are looking to achieve, is this program of use to you?

  • Like 1

Share this post


Link to post
Share on other sites
Pugazh
10 hours ago, Lee Mac said:

@Pugazh Assuming I've understood what you are looking to achieve, is this program of use to you?

thank you lee :) i got it your code :) :beer:

Share this post


Link to post
Share on other sites
Lee Mac
7 hours ago, Pugazh said:

thank you lee :) i got it your code :) :beer:

 

Excellent - you're most welcome :)

  • Like 1

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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