Author Topic: Rotating Text in an MLeader  (Read 1646 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Rotating Text in an MLeader
« on: June 28, 2016, 01:48:13 PM »
I'm trying to rotate text in an MLeader, but ending up with weird results.

For some/most labels it works, but sometimes the text conflicts with the leaderline. If I double click on the endpoint of the leader, the text corrects it's self to the correct side (wanted.png)

Here's the code I'm using:
Code - C#: [Select]
  1. private static void SetLabelRotation(IEnumerable<ObjectId> labelIds, LockedTransaction acTr, double rotation)
  2. {
  3.         foreach (ObjectId id in labelIds)
  4.         {
  5.                 Entity ent = acTr.GetObject(id, OpenMode.ForWrite, false) as Entity;
  6.                 MLeader pipeLabel = ent as MLeader;
  7.                 if (pipeLabel != null)
  8.                 {
  9.                         // clone the old text and replace it
  10.                         MText oldText = pipeLabel.MText;
  11.                         MText newText = oldText.Clone() as MText;
  12.                         if (newText != null)
  13.                         {
  14.                                 // set the rotation
  15.                                 newText.Rotation = rotation;
  16.                                 pipeLabel.MText = newText;
  17.                                 // try resetting attachments? this doesn't work
  18.                                 newText.Attachment = AttachmentPoint.MiddleCenter;
  19.                                 pipeLabel.TextAttachmentType = TextAttachmentType.AttachmentMiddle;
  20.                         }
  21.                 }
  22.         }
  23. }

I could just recreate the mleader, but I'd really like to keep the same one because I write it's handle to the polyline it's describing. Any ideas?
« Last Edit: June 28, 2016, 02:16:10 PM by Atook »

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Rotating Text in an MLeader
« Reply #1 on: June 28, 2016, 09:04:26 PM »
sometimes I've found that you need to add the new MText object to the db before fine tuning the properties and making them stick.
hth
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien