.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adjusting appearance of leader drawn with VB.NET

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
laurie.comerford
1246 Views, 3 Replies

Adjusting appearance of leader drawn with VB.NET

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
3 REPLIES 3
Message 2 of 4
Jeff_M
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
EESignature
Message 3 of 4
laurie.comerford
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
Message 4 of 4
quyenpv
in reply to: laurie.comerford

I want to use the above DrawLeader function but how can I manually select the coordinates on the drawing without having to enter it as fixed as the code above

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost