.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to set the plot style none

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
e.g.
1041 Views, 8 Replies

How to set the plot style none

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.

 

 

 

8 REPLIES 8
Message 2 of 9
SENL1362
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.
Message 3 of 9
e.g.
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.

Message 4 of 9
SENL1362
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.
Message 5 of 9
e.g.
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.

Message 6 of 9
SENL1362
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

 

 

 

 

 

 

Message 7 of 9
SENL1362
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.

Message 8 of 9
e.g.
in reply to: SENL1362

Hi SENL1362,

 

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

 

e.g.

Message 9 of 9
SENL1362
in reply to: e.g.

you're welcome

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost