<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multi-line Leader Text Only Left Justified in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8630578#M23324</link>
    <description>&lt;P&gt;Hello Gile,&lt;/P&gt;
&lt;P&gt;Thank you very much for that, it did the trick.&amp;nbsp; I didn't know about the mleader.MoveMLeader command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
    <pubDate>Fri, 01 Mar 2019 16:15:46 GMT</pubDate>
    <dc:creator>mgorecki</dc:creator>
    <dc:date>2019-03-01T16:15:46Z</dc:date>
    <item>
      <title>Multi-line Leader Text Only Left Justified</title>
      <link>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8629138#M23322</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;The code I'm using to insert my mleaders will add the mleader either pointing to the left or right.&amp;nbsp; The problem is, when its pointing to the right, the text is still left justified within the bounding box.&lt;/P&gt;
&lt;P&gt;Is there a way to set the mtext justification?&lt;/P&gt;
&lt;PRE&gt;    Public Sub AddMLeader2(ByVal ldrPnt1 As Point3d, ByVal ldrPnt2 As Point3d, ByVal ldrTextVal As String, _
                          ByVal ldrTextWidth As Double, ByVal dwgTextHeight As Double)
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database

        Using mlTran As Transaction = db.TransactionManager.StartTransaction()
            Dim blkTbl As BlockTable = TryCast(mlTran.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
            Dim blkTblRec As BlockTableRecord = TryCast(mlTran.GetObject(blkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
            Dim mldr As MLeader = New MLeader()
            Dim mText As MText = New MText()
            mldr.SetDatabaseDefaults()

            ' Creates a new leader cluster
            Dim leaderNumber As Integer = mldr.AddLeader()

            ' Add a leader line to the cluster
            Dim leaderLineNum As Integer = mldr.AddLeaderLine(leaderNumber)
            mldr.AddFirstVertex(leaderLineNum, ldrPnt1)
            mldr.AddLastVertex(leaderLineNum, ldrPnt2)

            Dim direction As Double = 1.0
            If (ldrPnt2 - ldrPnt1).DotProduct(Vector3d.XAxis) &amp;lt; 0.0 Then direction = -1.0
            mldr.SetDogleg(leaderNumber, Vector3d.XAxis.MultiplyBy(direction))
            mText.Width = ldrTextWidth
            mText.Height = dwgTextHeight
            mText.Contents = ldrTextVal
            mldr.MText = mText

            blkTblRec.UpgradeOpen()
            blkTblRec.AppendEntity(mldr)

            mlTran.AddNewlyCreatedDBObject(mldr, True)
            mlTran.Commit()
        End Using
    End Sub&lt;/PRE&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 23:00:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8629138#M23322</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2019-02-28T23:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-line Leader Text Only Left Justified</title>
      <link>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8630043#M23323</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=OREFNET-Autodesk_AutoCAD_DatabaseServices_MLeader_MoveMLeader_Vector3d_Autodesk_AutoCAD_DatabaseServices_MoveType" target="_blank" rel="noopener"&gt;MLeader.MoveMLeader()&lt;/A&gt; method with MoveType.MoveContentAndDoglegPoints and a vector which length equals: (MLeader.GoglegLength + MLeader.LandingGap) * 2 + MText.ActualWidth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems to me you do not need to use the DotProduct, you can simply compare the start point and end end point X coordinates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        static void AddMleader(Point3d startPoint, Point3d endPoint, string textContents, double textWidth, double textHeight)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var mleader = new MLeader();
                mleader.SetDatabaseDefaults();
                mleader.ContentType = ContentType.MTextContent;
                int index = mleader.AddLeader();
                mleader.AddLeaderLine(index);
                mleader.AddFirstVertex(index, startPoint);
                mleader.AddLastVertex(index, endPoint);

                MText mtext = new MText();
                mtext.SetDatabaseDefaults();
                mtext.Width = textWidth;
                mtext.Height = textHeight;
                mtext.Contents = textContents;

                mleader.MText = mtext;
                mtext.Location = mleader.TextLocation;
                if (endPoint.X &amp;lt; startPoint.X)
                {
                    var offset = (mleader.DoglegLength + mleader.LandingGap) * 2 + mtext.ActualWidth;
                    mleader.MoveMLeader(Vector3d.XAxis * -offset, MoveType.MoveContentAndDoglegPoints);
                }

                var cSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                cSpace.AppendEntity(mleader);
                tr.AddNewlyCreatedDBObject(mleader, true);
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Mar 2019 12:26:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8630043#M23323</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-01T12:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Multi-line Leader Text Only Left Justified</title>
      <link>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8630578#M23324</link>
      <description>&lt;P&gt;Hello Gile,&lt;/P&gt;
&lt;P&gt;Thank you very much for that, it did the trick.&amp;nbsp; I didn't know about the mleader.MoveMLeader command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 16:15:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multi-line-leader-text-only-left-justified/m-p/8630578#M23324</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2019-03-01T16:15:46Z</dc:date>
    </item>
  </channel>
</rss>

