<CommandMethod("mn", CommandFlags.UsePickSet)> _
Public Sub TestMleaderNET()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim dem As String = "+"
Dim txtId As ObjectId = ObjectId.Null
Dim mtx As MText
Dim mlines As New List(Of String)()
Dim opts As New PromptEntityOptions(vbLf & "Select a leader or mleader")
opts.SetRejectMessage(vbLf & "Select leader or mleader only!")
opts.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.Leader), False)
opts.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.MLeader), False)
Dim res As PromptEntityResult = ed.GetEntity(opts)
If res.Status <> PromptStatus.OK Then
Return
End If
Try
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim ent As Entity = TryCast(tr.GetObject(res.ObjectId, OpenMode.ForRead), Entity)
Dim lead As Leader = TryCast(ent, Leader)
If lead IsNot Nothing Then
If lead.AnnoType = AnnotationType.MText Then
txtId = lead.Annotation
mtx = TryCast(DirectCast(tr.GetObject(txtId, OpenMode.ForRead), MText), MText)
Dim cont As String = mtx.Text
' check if the string contains a desired delimiter (eg "+")
If Not cont.Contains(dem) Then
Return
End If
mlines = New List(Of String)()
mlines
= cont
.Split("+"c
).ToList()
Dim sb As New StringBuilder()
For Each st As String In mlines
sb.AppendLine(st)
Next
mtx.UpgradeOpen()
lead.UpgradeOpen()
' new text string
' use other settings to place text below, see properties in the Intellisence drop down box
mtx.Contents = sb.ToString()
End If
End If
Dim mlead As MLeader = TryCast(ent, MLeader)
If mlead IsNot Nothing Then
If mlead.ContentType = ContentType.MTextContent Then
mtx = New MText()
mtx = DirectCast(mlead.MText, MText)
Dim cont As String = mtx.Contents
' check if the string contains a desired delimiter (eg "+")
If Not cont.Contains(dem) Then
Return
End If
mlines = New List(Of String)()
mlines
= cont
.Split("+"c
).ToList()
Dim sb As New StringBuilder()
For Each st As String In mlines
sb.AppendLine(st)
Next
mlead.UpgradeOpen()
mtx.Contents = sb.ToString()
' new text string
' use other settings to place text below, see properties in the Intellisence drop down box
mlead.MText = mtx
End If
End If
tr.Commit()
End Using
Catch ex As System.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message)
'empty field
Finally
End Try
End Sub