Jump to content

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


Pugazh

Recommended Posts

(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
Link to comment
Share on other sites

  • Pugazh changed the title to Setvar 'Snapang using lisp with greater-than or equal condition
(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:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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

 

Link to comment
Share on other sites

(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
Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

    (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 :( 

Link to comment
Share on other sites

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
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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