Gets and sets the current plot style for a layout

By Virupaksha Aithal

This example adds a command named “SetPlotSheet”. When this command is run all of the available plot sheets are listed on the command line. Also if the drawing is using .ctb files the stylesheet for the layout is set to “acad.ctb” if it is one of the available style sheets.

[CommandMethod("SetPlotSheet")]
public void SetPlotSheet()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        LayoutManager layManager = LayoutManager.Current;
        ObjectId layoutId = 
                   layManager.GetLayoutId(layManager.CurrentLayout);
 
        Layout layoutObj = 
                   (Layout)tr.GetObject(layoutId, OpenMode.ForWrite);
 
        ed.WriteMessage("Style sheet of current layout: " 
                                + layoutObj.CurrentStyleSheet + "n");
 
        PlotSettingsValidator plotSetVal = 
                                       PlotSettingsValidator.Current;
        plotSetVal.RefreshLists(layoutObj);
 
        System.Collections.Specialized.StringCollection sheetList 
                                = plotSetVal.GetPlotStyleSheetList();
        ed.WriteMessage("The list of available plot style sheetsn");
        foreach (String str in sheetList)
        {
            ed.WriteMessage(str + "n");
            if (str.ToLower().Equals("acad.ctb"))
            {
                //find out if drawing is using ctb
                System.Object test = 
                    Application.GetSystemVariable("PSTYLEMODE");
                if (test.ToString().Equals("1"))
                {
                    // drawing is using ctb so go ahead and 
                    //assign acad.ctb to the layout
                    ed.WriteMessage("nThe plot style sheet is" +
                                       " being set to acad.ctbnn");
                    plotSetVal.SetCurrentStyleSheet(layoutObj, str);
                }
                else
                {
                    ed.WriteMessage("nUnable to set plot style in" +
                            " this example, drawing using stbnn");
                }
            }
        }
        tr.Commit();
    }
}

Comments

2 responses to “Gets and sets the current plot style for a layout”

  1. Is this code run without exception?I try to run,but at the line :plotSetVal.SetCurrentStyleSheet(layoutObj, str);threw an exception,says eInvalid input…,and I check the help file,is says the first parameter should be PlotSettings instead of Layout.
    Actually,my problem is no matter what style sheet I set,the line in the ploted file(pdf) always has it’s color,but I want them all black.
    Any suggestions?thank you.

  2. Just found out that one needs to say “Use the Stylesetting”.
    Thus in VB this line:
    acPlotSetValidator.SetCurrentStyleSheet (acPlotSettings, StyleSheet)
    is followed by:
    acPlotSettings.PlotPlotStyles = True
    That works for me. (after few months of pulling my hear out)

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading