public static double checkAngle(double angle)
{
if (angle >= 0 && angle < PI / 2)
{
//angle = angle;
}
else if (angle >= PI / 2 && angle < PI)
{
angle = angle - PI;
}
else if (angle >= PI && angle < PI + PI / 2)
{
angle = angle - PI;
}
else if (angle >= PI + PI / 2 && angle < PI + PI / 2)
{
angle = angle - 2 * PI;
}
return angle;
}
Thanks badjo, that's what I was trying to write but I not sure if it will work correctly all the time .
Thanks Stefan,
Can you please explain that function and the way it works ? I can't get it to work but when I added (/ pi 2.0) worked but not as expected and it fails in most cases to give the right rotation as explained in photo above.
Sorry Stefan, but that was not the same as my example.If it's on the top side already but you want it on the opposite side wouldn't that be the bottom ? :?
Number 16 located above the line but it has to be on the opposite side.
Sorry Stefan, but that was not the same as my example.
Number 16 located above the line but it has to be on the opposite side.
I am trying to locate one similar text ( 125 ) on line objects on the top...Now is more confusing... Do you want some text above and some below? They are all "125", which one are you trying to fix?
Sorry Stefan, but that was not the same as my example.If it's on the top side already but you want it on the opposite side wouldn't that be the bottom ? :?
Number 16 located above the line but it has to be on the opposite side.
Sorry Stefan, but that was not the same as my example.
Number 16 located above the line but it has to be on the opposite side.
I'm really sorry, I didn't read carefully your request, I thought it's all about angles.I am trying to locate one similar text ( 125 ) on line objects on the top...Now is more confusing... Do you want some text above and some below? They are all "125", which one are you trying to fix?
The side which is anticlockwise is the top side.:? :wideeyed2:
(defun c:test (/ ss n obj start end lst ang pt center a)
(setq ss (ssget '((0 . "LINE"))))
(repeat (setq n (sslength ss))
(setq obj (ssname ss (setq n (1- n))))
(setq lst (entget obj))
(setq start (cdr (assoc 10 lst))
end (cdr (assoc 11 lst))
ang (angle start end)
center (polar start ang (/ (distance start end) 2.0))
)
(setq a (atan (/ (sin ang) (cos ang))))
(setq pt (polar center (- ang (/ pi 2)) 0.5))
(entmakex (list '(0 . "TEXT")
(cons 1 (rtos (distance start end) 2 0))
(cons 10 pt)
(cons 11 pt)
(cons 40 0.35)
(cons 50 a)
)
)
)
(princ)
)
Sorry, it does not work as expected.This request is confusing. It would help to post your sample drawing too so we don't have to try to recreate something we know little about. Are you sure you don't just need a 'make text readable' function?
Can you please check if the codes are correct with your codes?Code: [Select](defun c:test (/ ss n obj start end lst ang pt center a)
(setq ss (ssget '((0 . "LINE"))))
(repeat (setq n (sslength ss))
(setq obj (ssname ss (setq n (1- n))))
(setq lst (entget obj))
(setq start (cdr (assoc 10 lst))
end (cdr (assoc 11 lst))
ang (angle start end)
center (polar start ang (/ (distance start end) 2.0))
)
(setq a (atan (/ (sin ang) (cos ang))))
(setq pt (polar center (- ang (/ pi 2)) 0.5))
(entmakex (list '(0 . "TEXT")
(cons 1 (rtos (distance start end) 2 0))
(cons 10 pt)
(cons 11 pt)
(cons 40 0.35)
(cons 50 a)
)
)
)
(princ)
)
atan can take 1 or 2 arguments. For 2 arguments, returns an angle between 0 and 2pi, depending on the sign of the 2 arg. For 1 argument, returns an angle between -pi/2 and pi/2, which is exactly the range of the readable angles.
I give up on this. I'm sure you are nearly there, just a little push and you are done.
This request is confusing. It would help to post your sample drawing too so we don't have to try to recreate something we know little about. Are you sure you don't just need a 'make text readable' function?