• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Contributor
    Posts: 48
    Registered: ‎09-08-2006
    Accepted Solution

    Adjusting appearance of leader drawn with VB.NET

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

    Hi,

    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
    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.


    Regards,


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

     

    Regards

    Laurie Comerford
    Please use plain text.
    *Expert Elite*
    Posts: 3,115
    Registered: ‎07-22-2003

    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
                    acLdr.EvaluateLeader()
    

     

    Jeff_M, also a frequent Swamper
    Please use plain text.
    Active Contributor
    Posts: 48
    Registered: ‎09-08-2006

    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.

     

     

    Regards,

     

    Laurie Comerford

    Regards

    Laurie Comerford
    Please use plain text.