Edit Mleader style

By Virupaksha Aithal

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();
    }
}

Comments

3 responses to “Edit Mleader style”

  1. sybold Avatar
    sybold

    this works for textheight, color, and most other properties, but setting the scale doesn’t work. how can that be done.
    the value does not transfer to the mleader when changed in the style.

  2. Hi
    How we change Style to block and block source to Box.
    thanks

  3. TY NGUYEN Avatar
    TY NGUYEN

    Hi all guys!
    Can we purge MleaderStyle not use in drawing by CAD.net?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading