Hello,
I am using a custom plot to pdf routine(Autocad 2012 x64); everything works ok, I can assign different plot styles but for some reason I cannot assign the "none" after I used a different ctb file. A snippet is bellow:
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(spaceId, OpenMode.ForRead);
Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
// We need a PlotInfo object linked to the layout
PlotInfo pi = new PlotInfo();
pi.Layout = btr.LayoutId;
// We need a PlotSettings object based on the layout settings which we then customize
PlotSettings ps = new PlotSettings(lo.ModelType);
ps.CopyFrom(lo);
// The PlotSettingsValidator helps create a valid PlotSettings object
PlotSettingsValidator psv = PlotSettingsValidator.Current;
..........
psv.SetCurrentStyleSheet(ps, "none");
......
When trying to assign the "none", the code fails. I don't know what I am missing (if I am not wrong it used to work with Autocad 2010?)
Thank you very much, and I appreciate your suggestions.
e.g.
Solved! Go to Solution.
Solved by SENL1362. Go to Solution.
Hi SENL1362,
setting it as "" instead of "none" is working, I don't get the error anymore; however when I check the layout.CurrentStyleSheet it is not changed; I cannot find the method RefreshPlotDeviceInfo though and I feel that this will be the answer.
I need to "refresh" the change and I don't know how.
Thanks,
e.g.
with some creativity on an old laptop and an old AutoCAD 2010 version, this sample changes the SheetStyle to None after another style has been used in the current layout
After NETLOADing use:
Command> SPS 2
==> set acad.stb current
Command> SPS 1
==> set None current
//Modified version of // Gets and sets the current plot style for a layout // By Virupaksha Aithal // http://adndevblog.typepad.com/autocad/2012/07/gets-and-sets-the-current-plot-style-for-a-layout.html // Also credits to KEAN WALMSLEY for his samples using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.PlottingServices; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; namespace PlotStyle { public class Class1 { [CommandMethod("SPS")] public void SwitchPlotSheetToNone() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PlotSettingsValidator plotSetVal = PlotSettingsValidator.Current; //not required to update the sheetlist when new sheetstyles are added after Acad startup, // use plotSetVal.RefreshLists(layout) instead //PlotConfigManager.RefreshList(RefreshCode.RefreshStyleList); int ctbStyle = System.Convert.ToInt32(Application.GetSystemVariable("PSTYLEMODE")); if (ctbStyle == 0) { ed.WriteMessage("\nError: Named PlotStyles drawings not supported!\nSee 'convertpstyles'"); return; } //Switch to Paperspace db.TileMode = false; using (Transaction tr = db.TransactionManager.StartTransaction()) { LayoutManager layoutManager = LayoutManager.Current; ObjectId layoutId = layoutManager.GetLayoutId(layoutManager.CurrentLayout); Layout layout = (Layout)tr.GetObject(layoutId, OpenMode.ForWrite); ed.WriteMessage("\nStyle sheet(before): {0}", layout.CurrentStyleSheet.Length == 0 ? "None" : layout.CurrentStyleSheet); plotSetVal.RefreshLists(layout); System.Collections.Specialized.StringCollection sheetList = plotSetVal.GetPlotStyleSheetList(); //Filter for CTB and add None, because None is not included in the PlotStyleSheetList from PlotSettingsValidator var ctbList=sheetList.Cast<string>().Where(n => Regex.IsMatch(n,".ctb", RegexOptions.IgnoreCase)).ToList();
//or use this returning a fullpathname list of CTB styles:
ctbList = PlotConfigManager.ColorDependentPlotStyles.Cast<string>().ToList();
ctbList.Insert(0, "None"); ed.WriteMessage("\nAvailable CTB's:"); //int i = 0; //ctbList.ForEach(n => ed.WriteMessage("\n{0}: {1}", ++i, n)); ctbList.Select((n, i) => string.Format("{0}: {1}", i + 1, n)).ToList().ForEach(n => ed.WriteMessage("\n{0}", n)); PromptIntegerOptions pio = new PromptIntegerOptions("\nEnter Style Sheet Number:"); pio.AllowNegative = false; pio.AllowZero = false; pio.LowerLimit = 1; pio.UpperLimit = ctbList.Count; PromptIntegerResult pir = ed.GetInteger(pio); if (pir.Status != PromptStatus.OK) return; string styleSheet = ctbList[pir.Value - 1]; if (styleSheet == "None") styleSheet = ""; plotSetVal.SetCurrentStyleSheet(layout, styleSheet); ed.WriteMessage("\nStyle sheet(after): {0}", layout.CurrentStyleSheet.Length == 0 ? "None" : layout.CurrentStyleSheet); tr.Commit(); } } } }
One more thing.
Looking at you're code you are modifying a copy of the Layout Plot Settings:
ps.CopyFrom(lo);
psv.SetCurrentStyleSheet(ps, "none");
To make these changes permanent you have to save ps back to the layout.
Can't find what you're looking for? Ask the community or share your knowledge.