Adding new TextStyleRecord/MLeaderStyle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a some working code that checks for the existence of a text style, and creates it if it does not exist. It then checks for the existence of an mleader style and creates it if it does not exist. It then adds a new mleader object. This new mleader style uses the new text style.
The code works great, but there is one thing I do not understand. If the text style that the mleader style uses already exists, then new mleaders are created with no problem regardless of what the current text style is set to. But, if the text style does not exist, I had to make the new text style current in order for the new mleaders I added to the drawing show with the proper text style (even though the new mleader style is set correctly to the new text style).
Am I doing somthing wrong?
<SNIP>
Dim mlstyleid As ObjectId
Dim m As MLeader = New MLeader()
m.LeaderLineType = LeaderType.StraightLeader
'Set mleader points from user picks
m.AddLeaderLine(arrowPoint)
m.AddLastVertex(0, symbolPoint)
Dim mlname As String = strMlStyle
Dim dict As DBDictionary = CType(acTrans.GetObject(acDb.MLeaderStyleDictionaryId, OpenMode.ForRead), DBDictionary)
If Not dict.Contains(strMlStyle) Then
Dim newMleadStyle As New MLeaderStyle()
newMleadStyle.PostMLeaderStyleToDb(acDb, mlname)
newMleadStyle.Annotative = AnnotativeStates.[True]
newMleadStyle.DrawMLeaderOrderType = DrawMLeaderOrderType.DrawLeaderFirst
newMleadStyle.LeaderLineColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, 256)
newMleadStyle.TextAlignAlwaysLeft = True
newMleadStyle.LeaderLineType = LeaderType.StraightLeader
newMleadStyle.ContentType = ContentType.MTextContent
newMleadStyle.ArrowSize = 0.09375
newMleadStyle.BreakSize = 0.0625
newMleadStyle.DoglegLength = 0.125
newMleadStyle.EnableLanding = True
newMleadStyle.EnableDogleg = True
newMleadStyle.EnableFrameText = False
newMleadStyle.LandingGap = 0.0625
newMleadStyle.MaxLeaderSegmentsPoints = 2
' Get the objectID of the ECDT text style
Dim textStyleTbl As TextStyleTable = acDb.TextStyleTableId.GetObject(OpenMode.ForRead)
Dim TxtRcd As TextStyleTableRecord
Dim newTxtRcd As New TextStyleTableRecord
If textStyleTbl.Has("ECDT") Then
TxtRcd = textStyleTbl("ECDT").GetObject(OpenMode.ForRead)
Else
' If text style does not exist, create it
newTxtRcd.Name = "ECDT"
textStyleTbl.UpgradeOpen()
textStyleTbl.Add(newTxtRcd)
Dim acNewFont As Autodesk.AutoCAD.GraphicsInterface.FontDescriptor
acNewFont = New Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("Century Gothic", False, False, 0, 0)
newTxtRcd.Font = acNewFont
acTrans.AddNewlyCreatedDBObject(newTxtRcd, True)
TxtRcd = textStyleTbl("ECDT").GetObject(OpenMode.ForRead)
End If
acDb.Textstyle = TxtRcd.ObjectId
newMleadStyle.TextStyleId = TxtRcd.ObjectId
<SNIP>
TIA