Active Contributor
Posts: 48
Registered: ‎09-08-2006
Message 1 of 3 (468 Views)
Accepted Solution

Adjusting appearance of leader drawn with VB.NET

468 Views, 2 Replies
10-12-2011 03:46 AM


Using some slightly modified code from the samples provided by Autodesk as shown below I'm attempting to draw a simple leader with MText annotation.

In the attached bitmap the top leader shows the result of running the code and the bottom one the appearance I want which is obtained by changing the AutoCAD properties of the leader under

Text pos vert
from 'Above' to 'Centered'

I can't identify anything in the API which allows me to draw with this change, but feel it should be there, so help is needed.

Searching the web for code to draw leaders, basically only returns minor variations on this code with only the same functionality.


Laurie Comerford


   <CommandMethod("TDD")> _
        Public Sub TestDrawLeader()
        DrawLeader("Here it is", New Point3d(0, 0, 0), New Point3d(15, 5, 0))
    End Sub ' AddLeaderAnnotation

    ''' <summary>
    '''  Called from:  AddLeaderAnnotation
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function DrawLeader(ByVal spText As String, ByVal pPtStart As Point3d, ByVal pPtEnd As Point3d) As Boolean
        Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim acBlkTbl As BlockTable
        Dim acBlkTblRec As BlockTableRecord
            ' Start a transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                ' Open the Block table for read
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
                ' Open the Block table record Model space for write
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                ' Create the MText annotation
                Dim acMText As MText = New MText()
                acMText.Contents = spText
                acMText.Location = New Point3d(pPtEnd.X + 7, pPtEnd.Y, 0)
                acMText.Attachment = AttachmentPoint.MiddleLeft
                acMText.Width = 0
                ' Add the new object to Model space and the transaction
                acTrans.AddNewlyCreatedDBObject(acMText, True)

                ' Create the leader with annotation
                Dim acLdr As Leader = New Leader
                acLdr.AppendVertex(New Point3d(pPtEnd.X + 5, pPtEnd.Y, 0))
                acLdr.HasArrowHead = True
                ' Add the new object to Model space and the transaction
                acTrans.AddNewlyCreatedDBObject(acLdr, True)
                ' Attach the annotation after the leader object is added
                acLdr.Annotation = acMText.ObjectId
                ' Commit the changes and dispose of the transaction
            End Using         
            Return True
        Catch ex As SystemException
            MsgBox("Unable to  with Function 'DrawLeader' due to:" & vbCrLf & Err.Description)
            Return False

        End Try
    End Function ' DrawLeader



Laurie Comerford
*Expert Elite*
Posts: 4,322
Registered: ‎07-22-2003
Message 2 of 3 (454 Views)

Re: Adjusting appearance of leader drawn with VB.NET

10-12-2011 07:19 AM in reply to: laurie.comerford

The DIMTAD property controls the position of the Mtext, it is initially set to the CUrrent Dimstyle's value. Override it for the leader to ensure it acts how you want.

                acLdr.Annotation = acMText.ObjectId
                acLdr.Dimtad = 0


Jeff_M, also a frequent Swamper
Active Contributor
Posts: 48
Registered: ‎09-08-2006
Message 3 of 3 (434 Views)

Re: Adjusting appearance of leader drawn with VB.NET

10-12-2011 12:57 PM in reply to: Jeff_M

Hi Jeff,


Thanks.   I'm only left with adding tables and creating the random drawing tools to get back to where the VBA code was 2 years ago. 


Shouldn't play so much golf I guess.





Laurie Comerford


Laurie Comerford
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.