Author Topic: MText Rotation Angle  (Read 2769 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
MText Rotation Angle
« on: October 16, 2013, 09:42:10 AM »
I'm trying to set the absolute rotation angle for an MText object, irrespective of the active UCS.

I realise that the rotation angle for MText is expressed relative to the active UCS, however, I cannot seem to determine the relationship between the active UCS (via UCSXDIR) and the direction of DXF group 11 when the MText rotation is set to zero and the UCS is not parallel with the MText plane.

As a workaround, I have tried altering the WCS vector held by DXF group 11 to the required direction, but cannot seem to alter this value (the entmod appears successful, but the MText object is not modified) unless the UCS matches the OCS of the MText object.

My last resort was to determine the angle of the DXF group 11 vector when the MText is at zero rotation, and then factor this into my calculations when amending the MText rotation, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (defun setmtextrotation ( ent rot / enx )
  2.     (setq enx (entget ent))
  3.     (entmod
  4.         (subst
  5.             (cons 50
  6.                 (- rot
  7.                     (angle '(0.0 0.0)
  8.                         (trans
  9.                             (cdr
  10.                                 (assoc 11
  11.                                     (entget
  12.                                         (cdr
  13.                                             (assoc -1
  14.                                                 (entmod
  15.                                                     (subst '(50 . 0.0) (assoc 50 enx) enx)
  16.                                                 )
  17.                                             )
  18.                                         )
  19.                                     )
  20.                                 )
  21.                             )
  22.                             0 (cdr (assoc 210 enx)) t
  23.                         )
  24.                     )
  25.                 )
  26.             )
  27.             (assoc 50 enx) enx
  28.         )
  29.     )
  30. )

But I figured there had to be a better way...

Any advice is very much appreciated.  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: MText Rotation Angle
« Reply #1 on: October 16, 2013, 10:51:58 AM »
I'm using this but this may be the method you are getting bad results from.
Code: [Select]
    (defun setmtextrotation ( ent rot / enx )
          (setq ucszdir (trans '(0 0 1) 1 0 T)
                rot     (- rot (angle '(0 0) (trans (getvar "UCSXDIR") 0 ucszdir))))
       (setq enx (entget ent))
       (entmod
           (subst
               (cons 50 rot)
               (assoc 50 enx) enx
           )
       )
    )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: MText Rotation Angle
« Reply #2 on: October 16, 2013, 11:20:06 AM »
Oddly, that method now appears to work with any MText that I test it with, though, with my original tests, I thought I was certain that method was returning incorrect results - maybe I had been looking at it for too long  :ugly:

Thanks CAB - I'll do some more testing and see if this holds up  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: MText Rotation Angle
« Reply #3 on: October 16, 2013, 11:47:42 AM »
I too often chase my tail. Painful when you catch up to it though. 8)

Let us know if it fails.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Rod

  • Newt
  • Posts: 185
Re: MText Rotation Angle
« Reply #4 on: October 16, 2013, 09:13:27 PM »
Hi Lee,
Don't have time to test now, but here are some things to try
change the value through Activex rotation property
OR use Activex transformby method

Also the help files states
NOTE  A group code 50 (rotation angle in radians) passed as DXF input is converted to the equivalent direction vector (if both a code 50 and codes 11, 21, 31 are passed, the last one wins). This is provided as a convenience for conversions from text objects

Rod
"All models are wrong, some models are useful" - George Box

Bhull1985

  • Guest
Re: MText Rotation Angle
« Reply #5 on: October 21, 2013, 11:57:16 AM »
As a workaround, I have tried altering the WCS vector held by DXF group 11 to the required direction, but cannot seem to alter this value (the entmod appears successful, but the MText object is not modified) unless the UCS matches the OCS of the MText object.

Any advice is very much appreciated.  :-)

Know this may be a bit too simple to be correct but did you (command "regen") after the entmod? I believe I ran into something that 'appeared' to work correctly but 'appeared' to not work correctly at the same time, the regen was the fix. Obviously you'd be aware of such things but when dealing with the complex sometimes the simple slips by...so just hoping pointing it out may be of assistance for you

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: MText Rotation Angle
« Reply #6 on: October 21, 2013, 06:03:54 PM »
did you (command "regen") after the entmod?

Yes, I believe I tried that when testing.
I haven't had a chance to revisit this project but hope to get some time soon.

Thank you all for your responses  :-)