.NET

Reply
Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 1 of 9 (400 Views)
Accepted Solution

How to set the plot style none

400 Views, 8 Replies
01-03-2014 10:54 AM

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.

 

 

 

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

 Clipboard-1.png

 

 

 

 

 

 

Mentor
SENL1362
Posts: 232
Registered: ‎07-20-2011
Message 2 of 9 (392 Views)

Re: How to set the plot style none

01-03-2014 11:32 AM in reply to: e.g.
i once used this:
Dim tmpLayout As AcadLayout
tmpLayout.RefreshPlotDeviceInfo
tmpLayout.ConfigName = "None"
tmpLayout.StyleSheet = ""
tmpLayout.RefreshPlotDeviceInfo

So try "" for the stylesheet==None.
Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 3 of 9 (372 Views)

Re: How to set the plot style none

01-03-2014 01:52 PM in reply to: SENL1362

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.

Mentor
SENL1362
Posts: 232
Registered: ‎07-20-2011
Message 4 of 9 (367 Views)

Re: How to set the plot style none

01-03-2014 02:08 PM in reply to: e.g.
I currently have no environment to test this and have no samples to look at the code.
Some weeks ago i wrote a program to create NamedPlotStyles and this program needed a lot refreshes to get it working.
It's not setting the CTB to NONE but we can try to set it.

On Monday i can have a look and send you the code if still needed.
Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 5 of 9 (362 Views)

Re: How to set the plot style none

01-03-2014 02:19 PM in reply to: SENL1362

Thank you, I appreciate your help; I'll let you know on Monday if I don't find it till then.

 

thanks,

 

e.g.

Mentor
SENL1362
Posts: 232
Registered: ‎07-20-2011
Message 6 of 9 (349 Views)

Re: How to set the plot style none

01-04-2014 03:09 PM in reply to: 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(); } } } }

 Clipboard-1.png

 

 

 

 

 

 

Mentor
SENL1362
Posts: 232
Registered: ‎07-20-2011
Message 7 of 9 (338 Views)

Re: How to set the plot style none

01-04-2014 03:44 PM in reply to: SENL1362

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.

Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 8 of 9 (287 Views)

Re: How to set the plot style none

01-06-2014 07:26 AM in reply to: SENL1362

Hi SENL1362,

 

thank you very, very much, your code saved me a lot of time.

 

e.g.

Mentor
SENL1362
Posts: 232
Registered: ‎07-20-2011
Message 9 of 9 (278 Views)

Re: How to set the plot style none

01-06-2014 08:36 AM in reply to: e.g.
you're welcome
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.