Get an angle from a Block.

Get an angle from a Block.

Anonymous
Not applicable
873 Views
3 Replies
Message 1 of 4

Get an angle from a Block.

Anonymous
Not applicable

Hello,

 

My problem is that I need to get an angle from a Block.

 

But instead to get the angle that I have in my personal UCS, it gets the angle that I I have at UCS - World.

 

I need the angle in my personal UCS, I hope someone could help me.

 

Thanks in advance.

 

The routine is this

 

 

(defun getAngleBlock (/)
  (setq ent (entsel "\nPunto para conectar el codo:\n"))
  (setq ent (entget (car ent)))
  (setq rot_bloque (cdr (assoc 50 ent)))
  (prompt (strcat "\nThe angle obtained was this:" (angtos rot_bloque 0 4)))
  (prin1)
  )

(defun c:GA (/)
  (getAngleBlock)
  )

And the block is attached.

 

 

 

 

 

 

 

0 Likes
874 Views
3 Replies
Replies (3)
Message 2 of 4

elshawadfy
Collaborator
Collaborator

The modified code included  finds the angle of current x axis (arctan x,y of the current x axis stored in the "UCSXDIR" system variable), and then substracts it from the object anle stored in its properties to calculate the current angle according to current ucs..

(defun getAngleBlock (/ ent rot_bloque)
  (setq ent (entsel "\nPunto para conectar el codo:\n"))
  (setq ent (entget (car ent)))
  (setq rot_bloque (cdr (assoc 50 ent)))
  (setq rot_bloque (- rot_bloque (atan (/ (car (getvar "UCSXDIR")) (cadr (getvar "UCSXDIR")) ))))
  (prompt (strcat "\nThe angle obtained was this:" (angtos rot_bloque 0 4)))
  (prin1)
  )
(defun c:GA (/)
  (getAngleBlock)
)
0 Likes
Message 3 of 4

stevor
Collaborator
Collaborator

May want to use the 'atan function with 2 arguments,

instead of a single that has the division,

to avoid the possible divide by zero.

 

 (setq rot_bloque (- rot_bloque (atan
     (car (getvar "UCSXDIR"))

     (cadr (getvar "UCSXDIR"))  )))

S
Message 4 of 4

elshawadfy
Collaborator
Collaborator

@stevor wrote:

May want to use the 'atan function with 2 arguments,

instead of a single that has the division,

to avoid the possible divide by zero.

 

 (setq rot_bloque (- rot_bloque (atan
     (car (getvar "UCSXDIR"))

     (cadr (getvar "UCSXDIR"))  )))


 

Thank you very much Stevor!! 

 

Yes you're wright.. That would be the correct apprauch..

0 Likes