.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Adjusting appearance of leader drawn with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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.ModelS pace), 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
Laurie Comerford
Solved! Go to Solution.
Re: Adjusting appearance of leader drawn with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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()
Re: Adjusting appearance of leader drawn with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Laurie Comerford
