Author Topic: MLeader attaching to the wrong side of MText  (Read 2104 times)

0 Members and 1 Guest are viewing this topic.

zoltan

  • Guest
MLeader attaching to the wrong side of MText
« on: August 04, 2011, 06:46:25 PM »
I am trying to create a MLeader that attaches to the right side of the MText when the leader is going to the left.  For some reason, it is attaching to the wrong side.

Code: [Select]
[CommandMethod("TestMLeader", "TestMLeader", "TestMLeader", CommandFlags.Modal)]
        public void TestMLeader()
        {
            Document acadDocument = Application.DocumentManager.MdiActiveDocument;
            using (Transaction trans = acadDocument.TransactionManager.StartTransaction())
            {
                BlockTable acadBlockTable = (BlockTable)trans.GetObject(acadDocument.Database.BlockTableId, OpenMode.ForRead);

                BlockTableRecord modelSpace = (BlockTableRecord)trans.GetObject(acadBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                //Leader to the right.
                MLeader leader1 = new MLeader();
                leader1.AddLeader();
                leader1.AddLeaderLine(0);
                leader1.AddFirstVertex(0, new Point3d(0.0, 0.0, 0.0));
                leader1.AddLastVertex(0, new Point3d(2.0, -2.0, 0.0));
                leader1.SetDatabaseDefaults();

                leader1.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
                leader1.TextAngleType = TextAngleType.HorizontalAngle;

                leader1.TextAlignmentType = TextAlignmentType.LeftAlignment;
                leader1.TextAttachmentType = TextAttachmentType.AttachmentMiddleOfTop;

                MText mText1 = new MText();
                mText1.SetDatabaseDefaults();

                mText1.Contents = "Text\\PText\\PText";

                leader1.MText = mText1;

                modelSpace.AppendEntity(leader1);
                trans.AddNewlyCreatedDBObject(leader1, true);

                //Leader to the left.
                MLeader leader2 = new MLeader();
                leader2.AddLeader();
                leader2.AddLeaderLine(0);
                leader2.AddFirstVertex(0, new Point3d(0.0, 0.0, 0.0));
                leader2.AddLastVertex(0, new Point3d(-2.0, -2.0, 0.0));
                leader2.SetDatabaseDefaults();

                leader2.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
                leader2.TextAngleType = TextAngleType.HorizontalAngle;

                leader2.TextAlignmentType = TextAlignmentType.RightAlignment;
                leader2.TextAttachmentType = TextAttachmentType.AttachmentMiddleOfBottom;

                MText mText2 = new MText();
                mText2.SetDatabaseDefaults();

                mText2.Contents = "Text\\PText\\PText";

                leader2.MText = mText1;

                modelSpace.AppendEntity(leader2);
                trans.AddNewlyCreatedDBObject(leader2, true);

                trans.Commit();
            }
        }

Jeff H

  • Needs a day job
  • Posts: 6144
Re: MLeader attaching to the wrong side of MText
« Reply #1 on: August 04, 2011, 07:18:46 PM »
MLeader.SetDogleg

This is your original code  just hard-coded for an example.

Modified 2 lines in code that end with---//////////GET INDEX
Added 2 lines that end with----/////////USE SETDOGLOG

Code: [Select]

        [CommandMethod("TestMLeader", "TestMLeader", "TestMLeader", CommandFlags.Modal)]
        public void TestMLeader()
        {
            Document acadDocument = Application.DocumentManager.MdiActiveDocument;
            using (Transaction trans = acadDocument.TransactionManager.StartTransaction())
            {
                BlockTable acadBlockTable = (BlockTable)trans.GetObject(acadDocument.Database.BlockTableId, OpenMode.ForRead);

                BlockTableRecord modelSpace = (BlockTableRecord)trans.GetObject(acadBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                //Leader to the right.
                MLeader leader1 = new MLeader();
                int leader1index = leader1.AddLeader();//////////GET INDEX
                leader1.AddLeaderLine(0);
                leader1.AddFirstVertex(0, new Point3d(0.0, 0.0, 0.0));
                leader1.AddLastVertex(0, new Point3d(2.0, -2.0, 0.0));
                leader1.SetDatabaseDefaults();

                leader1.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
                leader1.TextAngleType = TextAngleType.HorizontalAngle;

                leader1.TextAlignmentType = TextAlignmentType.LeftAlignment;
                leader1.TextAttachmentType = TextAttachmentType.AttachmentMiddleOfTop;

                MText mText1 = new MText();
                mText1.SetDatabaseDefaults();

                mText1.Contents = "Text\\PText\\PText";

                leader1.MText = mText1;
                leader1.SetDogleg(leader1index, Vector3d.XAxis);/////////USE SETDOGLOG
                modelSpace.AppendEntity(leader1);
                trans.AddNewlyCreatedDBObject(leader1, true);

                //Leader to the left.
                MLeader leader2 = new MLeader();
                int leader2index = leader2.AddLeader();//////////GET INDEX
                leader2.AddLeaderLine(0);
                leader2.AddFirstVertex(0, new Point3d(0.0, 0.0, 0.0));
                leader2.AddLastVertex(0, new Point3d(-2.0, -2.0, 0.0));
                leader2.SetDatabaseDefaults();

                leader2.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
                leader2.TextAngleType = TextAngleType.HorizontalAngle;

                leader2.TextAlignmentType = TextAlignmentType.RightAlignment;
                leader2.TextAttachmentType = TextAttachmentType.AttachmentMiddleOfBottom;

                MText mText2 = new MText();
                mText2.SetDatabaseDefaults();

                mText2.Contents = "Text\\PText\\PText";

                leader2.MText = mText1;
                leader2.SetDogleg(leader2index, Vector3d.XAxis.MultiplyBy(-1));/////////USE SETDOGLOG
                modelSpace.AppendEntity(leader2);
                trans.AddNewlyCreatedDBObject(leader2, true);

                trans.Commit();
            }
        }

zoltan

  • Guest
Re: MLeader attaching to the wrong side of MText
« Reply #2 on: August 04, 2011, 10:43:46 PM »
I think that did it!

Thanks.