I am trying to create an mleader with mtext. I can create the leader and all is well until you save and reopen the drawing or if you copy the mleader. After either of these two events, the text of the mleader reverts to a height of 1.
The text inside the mleader is also not annotative and does not seem to respect the height or annotative settings. Am I missing something obvious or is this a bug?
<CommandMethod("TESTLabelCoords")> _
Public Sub LabelCoordinateWithMtext()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Try
' get the point
Dim ptOpts As New PromptPointOptions(vbLf & "Select a point to measure coordinate values: ")
Dim ptRes As PromptPointResult = ed.GetPoint(ptOpts)
'if ok then ask for mleader location and add coordinate values
If PromptStatus.OK = ptRes.Status Then
Dim p As Point3d = ptRes.Value
Dim txtOpts As New PromptPointOptions(vbLf & "Pick insertion point of label: ")
txtOpts.UseBasePoint = True
txtOpts.BasePoint = ptRes.Value
txtOpts.UseDashedLine = True
Dim txtRes As PromptPointResult = ed.GetPoint(txtOpts)
Dim txtval As String
If ptRes.Value.Z = 0 Then
txtval = ("N:" + FormatNumber(Math.Round(ptRes.Value.Y, 4), 4, , , TriState.False).ToString _
+ "\P" + "E:" + FormatNumber(Math.Round(ptRes.Value.X, 4), 4, , , TriState.False).ToString)
Else
txtval = ("N:" + FormatNumber(Math.Round(ptRes.Value.Y, 4), 4, , , TriState.False).ToString _
+ "\P" + "E:" + FormatNumber(Math.Round(ptRes.Value.X, 4), 4, , , TriState.False)).ToString _
+ "\P" + "ELEV:" + (FormatNumber(Math.Round(ptRes.Value.Z, 2), 2, , , TriState.False).ToString)
End If
If PromptStatus.OK = txtRes.Status Then
Dim mtLoc As Point3d = txtRes.Value
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Using tr
' Create our new MText and set its properties
Dim mt As New MText()
mt.Location = mtLoc
mt.Contents = txtval
mt.BackgroundFill = True
mt.BackgroundScaleFactor = 1.1
mt.Annotative = AnnotativeStates.True
mt.SetFromStyle()
mt.Height = 5
Dim ml As New MLeader()
Dim ldNum As Integer = ml.AddLeader()
Dim lnnum As Integer = ml.AddLeaderLine(ldNum)
ml.AddFirstVertex(lnnum, ptRes.Value)
ml.AddLastVertex(lnnum, txtRes.Value)
ml.Annotative = AnnotativeStates.True
Dim dict As DBDictionary = CType(tr.GetObject(db.MLeaderStyleDictionaryId, OpenMode.ForRead), DBDictionary)
Dim mlstyleid As ObjectId = dict.GetAt("G-080")
If Not mlstyleid = Nothing Then
ml.MLeaderStyle = mlstyleid
'ml.SetFromStyle()
End If
ml.MText = mt
'' check for preferred justification
If ptRes.Value.X > txtRes.Value.X Then
ml.TextAlignmentType = TextAlignmentType.RightAlignment
Else
ml.TextAlignmentType = TextAlignmentType.LeftAlignment
End If
' Open the block table, the model space and
' add our MText
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim ms As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Dim mlId = ms.AppendEntity(ml)
tr.AddNewlyCreatedDBObject(ml, True)
' Finally we commit our transaction
tr.Commit()
End Using
Else
ed.WriteMessage(vbCrLf + "A point was not selected ")
End If
Else
ed.WriteMessage(vbCrLf + "A point was not selected ")
End If
Catch e As System.Exception
ed.WriteMessage(vbLf & "Exception {0}.", e)
End Try
End Sub