Mleaderstyle objects are stored in the named object dictionary of the drawing database. Database object exposes an objectId “MLeaderStyleDictionaryId” to access this dictionary. Below code shows the procedure to edit a Mleader style. Below code edits only the mleader style’s text height and color, but Mleaderstyle object exposes many more properties to edit like “ArrowSymbolId”, “ArrowSize” “LandingGap” & etc.
[CommandMethod("EditMleaderStyle")]
static public void EditMleaderStyle()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr =
db.TransactionManager.StartTransaction())
{
//Name of the mleader Style to edit
const string styleName = "Standard";
DBDictionary mlstyles = (DBDictionary)tr.GetObject(
db.MLeaderStyleDictionaryId,
OpenMode.ForRead);
if (!mlstyles.Contains(styleName))
{
return;
}
ObjectId id = mlstyles.GetAt(styleName);
//now get the active mleader style
MLeaderStyle currentStyle = tr.GetObject(id,
OpenMode.ForWrite) as MLeaderStyle;
//now edit the style
currentStyle.TextColor =
Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0);
//just double the text height
currentStyle.TextHeight = currentStyle.TextHeight * 2;
tr.Commit();
}
}

Leave a Reply