List all available plot styles with .NET API

By Virupaksha Aithal

You need to iterate through the dictionary of plot style names in the Named Object Dictionary to find all plot styles available.  In the dictionary, each entry is a type of System.Collections.DictionaryEntry. Each DictionaryEntry object has a Key/Value pair of properties. The Key property is the name of the plot style and the value stores the Object ID of a PlaceHolder object.

[CommandMethod("ListPlotStyleName")]
static public void ListPlotStyleName()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    ObjectId psDictId = db.PlotStyleNameDictionaryId;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        DBDictionary dicObj = tr.GetObject(psDictId,
                                   OpenMode.ForRead) as DBDictionary;
 
        foreach (DBDictionaryEntry entry in dicObj)
        {
            //key will be name
            ed.WriteMessage(entry.Key + "n");
 
            //entry.Value will have object id of  PlaceHolder
        }
 
        tr.Commit();
    }
}

Comments

One response to “List all available plot styles with .NET API”

  1. Brent M. Avatar
    Brent M.

    This only lists plot styles that are currently being used. Any chance of finding a method to list ALL of the available plot styles, including those that haven’t yet been used in the drawing?

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading