' first I call this sub to create and set current a new MLeader style called "ColSupMLeader" Public Sub AddMleaderStyle() Dim ArialTxtStyle As ObjectId Using tr As Transaction = mydb.TransactionManager.StartTransaction() ' get "Arial" textstyle Dim acTextStyTbl As TextStyleTable acTextStyTbl = tr.GetObject(mydb.TextStyleTableId, OpenMode.ForRead) If acTextStyTbl.Has("Arial") = True Then ArialTxtStyle = acTextStyTbl("Arial") Else MsgBox("Arial textstyle not found") End If 'Name of the mleader Style to edit Const styleName As String = "ColSupMLeader" Dim mlstyles As DBDictionary = DirectCast(tr.GetObject(mydb.MLeaderStyleDictionaryId, OpenMode.ForRead), DBDictionary) Dim mLeaderStyle As ObjectId = ObjectId.Null If Not mlstyles.Contains(styleName) Then 'add a new mleader style... Dim newStyle As New MLeaderStyle() ''make the arrow head as DOT. 'Dim blockTable As BlockTable = TryCast(tr.GetObject(mydb.BlockTableId, OpenMode.ForRead), BlockTable) 'If Not blockTable.Has("_DOT") Then ' 'load ' Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("DIMBLK", "_DOT") 'End If 'now set style options newStyle.ArrowSize = 0.062 newStyle.ContentType = Autodesk.AutoCAD.DatabaseServices.ContentType.MTextContent newStyle.ArrowSymbolId = mydb.Dimldrblk ' standard closed filled arrowhead newStyle.DoglegLength = 0.09375 newStyle.TextStyleId = ArialTxtStyle newStyle.TextAlignmentType = TextAlignmentType.LeftAlignment newStyle.TextAlignAlwaysLeft = True newStyle.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal newStyle.TextAngleType = TextAngleType.AlwaysRightReadingAngle newStyle.SetTextAttachmentType(TextAttachmentType.AttachmentMiddle, LeaderDirectionType.LeftLeader) newStyle.SetTextAttachmentType(TextAttachmentType.AttachmentMiddle, LeaderDirectionType.RightLeader) newStyle.SetTextAttachmentType(TextAttachmentType.AttachmentMiddle, LeaderDirectionType.BottomLeader) newStyle.SetTextAttachmentType(TextAttachmentType.AttachmentMiddle, LeaderDirectionType.TopLeader) newStyle.SetTextAttachmentType(TextAttachmentType.AttachmentMiddle, LeaderDirectionType.UnknownLeader) ' newStyle.EnableFrameText = true ' Add Frame around text newStyle.LandingGap = 0.02 newStyle.LeaderLineColor = AcCol.Color.FromColorIndex(AcCol.ColorMethod.ByLayer, 256) newStyle.LeaderLineWeight = LineWeight.ByLayer newStyle.LeaderLineType = Autodesk.AutoCAD.DatabaseServices.LeaderType.StraightLeader newStyle.LeaderLineTypeId = mydb.ContinuousLinetype newStyle.DrawLeaderOrderType = DrawLeaderOrderType.DrawLeaderHeadFirst newStyle.DrawMLeaderOrderType = DrawMLeaderOrderType.DrawLeaderFirst newStyle.EnableLanding = True newStyle.FirstSegmentAngleConstraint = AngleConstraint.DegreesAny newStyle.MaxLeaderSegmentsPoints = 2 newStyle.LeaderLineType = LeaderType.StraightLeader newStyle.SecondSegmentAngleConstraint = AngleConstraint.DegreesAny newStyle.Annotative = AnnotativeStates.True ' set the style as current mLeaderStyle = newStyle.PostMLeaderStyleToDb(mydb, styleName) tr.AddNewlyCreatedDBObject(newStyle, True) Else mLeaderStyle = mlstyles.GetAt(styleName) End If 'set the new mleader as the current style mydb.MLeaderstyle = mLeaderStyle tr.Commit() End Using End Sub ' then in the main code i use this to create a mtext object then assign it to the mleader If DoLabel = True Then '' Open the Block table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(mydb.BlockTableId, OpenMode.ForRead) '' Open the Block table record Model space for write Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) ' Add column count Mtext Dim mytext As New MText mytext.TextHeight = 5 mytext.BackgroundFill = AecBldDb.Masking.BoundingBox If RailingStyleName.ToUpper = "RIDGEBEAM - HALF" Then mytext.Contents = ("(" & numstuds.ToString & ")" & "2x" & Math.Ceiling(wallthk).ToString) Else mytext.Contents = ("(" & numstuds.ToString & ")" & "2x" & Math.Ceiling(wallthk).ToString & " Per" & "\P" & "Module") End If '' Add the new object to Model space acBlkTblRec.AppendEntity(mytext) acTrans.AddNewlyCreatedDBObject(mytext, True) ' create a MLeader Dim mLeader As New MLeader Dim dict As DBDictionary = CType(acTrans.GetObject(mydb.MLeaderStyleDictionaryId, OpenMode.ForRead), DBDictionary) Dim mlstyleid As ObjectId = dict.GetAt("ColSupMLeader") '<--mleader style name mLeader.MLeaderStyle = mlstyleid ' determine direction for leader line Dim idx As Integer = mLeader.AddLeaderLine(PolarPoint3d(pt3d, (bmrot + (Math.PI / 4)), 24)) mLeader.AddFirstVertex(idx, pt3d) mLeader.Layer = "G-Anno-SubmitCodeFP-Dims" '' Add the new object to Model space and the transaction acBlkTblRec.AppendEntity(mLeader) acTrans.AddNewlyCreatedDBObject(mLeader, True) ' attach text to leader AFTER leader has been added to modelspace mLeader.MText = mytext mytext.Erase() ' acTrans.AddNewlyCreatedDBObject(mytext, True) adds unwanted pieces of text so erase them mytext = Nothing 'lets me re-use mytext variable for the next piece of text End If