Inserting a UCS angle value

Inserting a UCS angle value

Anonymous
Not applicable
1,600 Views
6 Replies
Message 1 of 7

Inserting a UCS angle value

Anonymous
Not applicable

Hello everyone,

 

I want to create a text which holds a specific alignment of X angle on UCS axis. Basically I am rotating my view regularly and I want it to understand to always rotate e.g. 45 degrees on my current and not world view. My code as of now is:

 

(setq gwnia (getint "\n Specify angle: "))

.......

(command "mtext" shelfnamep "j" "tc" "s" "driverstyle" "r" gwnia "w" "0.8" shelfname "" )

I thought about the trans function, but it says it works on points. Basically I don't even need to ask for the user input of the angle at the start of my code, I will always have a fixed 45 degrees on the text that pops up based on my current view.

0 Likes
Accepted solutions (1)
1,601 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

You want to insert MTEXT rotated 45° to current UCS. This should be enought.

 

(command "mtext" shelfnamep "j" "tc" "s" "driverstyle" "r" 45 "w" 0.8 shelfname "" )
0 Likes
Message 3 of 7

Anonymous
Not applicable

Maybe I'm phrasing my question wrong. 

What I mean is, I need to keep the orientation of the generated text rotating as I rotate my screen. e.g. if I am at the normal NESW (top and clockwise) view and I generate the text with 45 degrees and I then change my view to ESWN and execute the code, the text is generated to the old 45 degree based on the WCS and not on the 45 degree I'm currently seeing on my screen.

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

So you need the angle 45°to WCS....

 

0 Likes
Message 5 of 7

john.uhden
Mentor
Mentor

When you say you are rotating your screen, are you using DView;Twist?

Sounds to me that you are looking for a reactor that changes the rotation of text based on (getvar "viewtwist").

This is excerpted and adapted from my HTEXT routine, which makes selected text horizontal to the screen...

   (setq 2pi (* pi 2.0)
         ucsang (angle (trans '(0.0 0.0 0.0) 0 1)(trans '(1.0 0.0 0.0) 0 1))
         vtwist (rem (- 2pi (getvar "viewtwist")) 2pi)
         0ang   (+ ucsang vtwist)
        ;; So for your case...
        45ang (+ 0ang (/ pi 4))
   )

You just have to figure out what filter to use to ssget the text candidates, and then learn about reactors.

John F. Uhden

0 Likes
Message 6 of 7

Anonymous
Not applicable

Let me explain more in depth.

 

I want to generate text based on the orientation of my view. I don't need the already generated text to change when I do change views. For example I work in a drawing and the orientation is normal (NESW). If I set an arbitrary number of degrees there for my text with the following code excerpt: 

 

(setq gwnia (getint "\nPlease specify angle: "))
....
(setq shelfnamep (getpoint "\n Insert shelf name insertion point: "))
(setq shelfname (getstring T "\n Insert shelf base name: ")) 
.....
(command "mtext" shelfnamep "j" "tc" "s" "driverstyle" "r" gwnia "w" "0.8" shelfname "" )

I will have a constant alignment of the text, whatever the current view. The global value for my text angle will remain constant.

 

What I would prefer, would be when I change my orientation (e.g. ESWN with E in the place of North) the next text I generate through my command to also rotate with the axis and still have a relative "gwnia" angle to my current view.

 

0 Likes
Message 7 of 7

hak_vz
Advisor
Advisor
Accepted solution

@Anonymous wrote:

I will have a constant alignment of the text, whatever the current view. The global value for my text angle will remain constant. What I would prefer, would be when I change my orientation (e.g. ESWN with E in the place of North) the next text I generate through my command to also rotate with the axis and still have a relative angle to my current view.


Here you have two functions that return angle of current UCS relative to WCS, one in radians other in degrees. To preserve rotation of a text object relative to WCS in your function subtract rotation of current UCS from text rotation relative to WCS (stored in variable "gwnia") .  In command approach to generating mtext instead "gwnia" you should use:

(- gwnia (ucsangdeg))
(defun ucsangrad ( / v uv *error* vect_dot vect_mod asin acos )
    (defun *error* () (princ))
    (setq v '(1.0 0.0 0.0) uv (trans v 1 0 T))
    (defun vect_dot (v1 v2)(apply '+ (mapcar '* v1 v2)))
    (defun asin (x)
      (cond 
        ((and(> x -1.0)(< x 1.0)) (atan (/ x (sqrt (- 1.0 (* x x))))))
        ((= x -1.0) (* -1.0 (/ pi 2)))
        ((= x  1) (/ pi 2))
      )
    )
    (defun acos (x)(cond ((and(>= x -1.0)(<= x 1.0)) (-(* pi 0.5) (asin x))))) 
    (setq ang (acos (vect_dot v uv)))
    (if (and (< (cadr uv) 0.0) (> (car uv) 0.0)) (setq ang (* -1 ang)))
    ang
)

(defun ucsangdeg ( / v uv *error* vect_dot vect_mod asin acos )
    (defun *error* () (princ))
    (setq v '(1.0 0.0 0.0) uv (trans v 1 0 T))
    (defun rad_to_deg (rad)(* 180.0 (/ rad PI)))
    (defun vect_dot (v1 v2)(apply '+ (mapcar '* v1 v2)))
    (defun asin (x)
      (cond 
        ((and(> x -1.0)(< x 1.0)) (atan (/ x (sqrt (- 1.0 (* x x))))))
        ((= x -1.0) (* -1.0 (/ pi 2)))
        ((= x  1) (/ pi 2))
      )
    )
    (defun acos (x)(cond ((and(>= x -1.0)(<= x 1.0)) (-(* pi 0.5) (asin x))))) 
    (setq ang (acos (vect_dot v uv)))
    (if (and (< (cadr uv) 0.0) (> (car uv) 0.0)) (setq ang (* -1 ang)))
    (rad_to_deg ang)
)

  I hope this answer your question.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.