TheSwamp

Code Red => .NET => Topic started by: chriskroll on January 06, 2015, 05:19:55 PM

Title: Rotate MLeader Block
Post by: chriskroll on January 06, 2015, 05:19:55 PM
Does anyone know how I can rotate the block contained within a multileader?  The BlockRotation property of the MLeader object is problematic as changing it will also change where the "landing" line connects to the block.  Also, the BlockRotation property is 0.0 even when the Block appears rotated.

I have attached a sample file with a multileader that I would like to reset to horizontal.

Here is a code snippet:
Code - C#: [Select]
  1. using (Transaction trans = doc.TransactionManager.StartTransaction())
  2. {
  3.         MLeader ml = (MLeader)trans.GetObject(mlObjectId, OpenMode.ForWrite);
  4.  
  5.         if (ml.HasContent())
  6.         {
  7.                 if (ml.ContentType == ContentType.MTextContent)
  8.                 {
  9.                         MText mt = ml.MText.Clone() as MText;
  10.  
  11.                         mt.Rotation = 0.0d;
  12.                         ml.MText = mt;
  13.                 }
  14.                 else if (ml.ContentType == ContentType.BlockContent)
  15.                 {
  16.                         ml.BlockRotation = 0.0d; // Does nothing since BlockRotation is already 0.0d.
  17.                 }
  18.         }
  19.         trans.Commit();
  20. }
  21.  
Title: Re: Rotate MLeader Block
Post by: Kerry on January 06, 2015, 06:40:29 PM
Does
mleader.TextAngleType
help at all ?

options:
public enum TextAngleType
Name: Autodesk.AutoCAD.DatabaseServices.TextAngleType
Assembly: Acdbmgd, Version=20.0.0.0
public enum TextAngleType
{
    InsertAngle,
    HorizontalAngle,
    AlwaysRightReadingAngle
}


just a wildassedguess.
Title: Re: Rotate MLeader Block
Post by: chriskroll on January 07, 2015, 09:37:29 AM
Kerry,

TextAngleType is not quite helpful in my specific situation.  I ended up just rotating the entire MLeader to fix the angle.  To get the existing block angle, I exploded the MLeader and then grabbed the Rotation property of the BlockReference.  Here is the code snippet:

Code - C#: [Select]
  1. if (ml.ContentType == ContentType.BlockContent)
  2. {
  3.  
  4.         DBObjectCollection dbOC = new DBObjectCollection();
  5.         ml.Explode(dbOC);
  6.  
  7.         double existingBlockAngle = 0.0d;
  8.         foreach (DBObject dbo in dbOC)
  9.         {
  10.                 if (dbo.GetRXClass().Name == "AcDbBlockReference")
  11.                 {
  12.                         BlockReference br = (BlockReference)dbo;
  13.                         existingBlockAngle = br.Rotation;
  14.                         break;
  15.                 }
  16.         }
  17.  
  18.         Matrix3d fixedRotation = Matrix3d.Rotation( -1.0d * existingBlockAngle, Vector3d.ZAxis, ml.GetFirstVertex(0));
  19.         ml.TransformBy(fixedRotation);
  20. }
  21.