Author Topic: PlottingServices help  (Read 11346 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
PlottingServices help
« on: December 06, 2006, 02:44:15 PM »
I have been trying to plot using the PlottingServices.
I haven't been able to create even the simplest plot.

Does anyone have a code example they would like to share?
A very simple one would be very helpfull.
I'm trying to stay calm. :pissed:

Here is my code so far:
Code: [Select]
        static public void NETPlot()
        {
            // Set up some variables
            Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database ThisDB = ThisDrawing.Database;
            string fullDWGPath = @"C:\PlotTest.dwg";
            int Copies = 1;
            Object parms = null;
            string plotDeviceName = "WPI-8830-Full.pc3";
            string styleSheet = "WPI-88xx-Full.ctb";
            Point2d originPoint = new Point2d(0, 0);
            // Set up some PLOT specific variables
            PlotEngine pEng = PlotFactory.CreatePublishEngine();
            PlotInfo pInfo = new PlotInfo();
            PlotSettings pSet = new PlotSettings(true);
            PlotSettingsValidator pSetValid = PlotSettingsValidator.Current;

            PlotPageInfo pPInfo = new PlotPageInfo();
            PlotProgressDialog pProgDialog = new PlotProgressDialog(false, 1, true);
            PlotConfigManager.SetCurrentConfig(plotDeviceName);
            //PlotConfigInfo pConfigInfo = new PlotConfigInfo();
            PlotConfigManager.RefreshList(RefreshCode.All);
            StringCollection cMNs = PlotConfigManager.CurrentConfig.CanonicalMediaNames;
            string mediaName = cMNs[0].ToString();

            try
            {
                pSetValid.SetPlotConfigurationName(pSet, plotDeviceName, mediaName);
                // It was recommended to refresh lists before changing settings
                pSetValid.RefreshLists(pSet);

                //pSetValid.SetCanonicalMediaName(pSet, mediaName);
                pSetValid.SetCurrentStyleSheet(pSet, styleSheet);
                pSetValid.SetPlotCentered(pSet, false);
                pSetValid.SetPlotOrigin(pSet, originPoint);
                pSetValid.SetPlotPaperUnits(pSet, PlotPaperUnit.Inches);
                pSetValid.SetPlotRotation(pSet, PlotRotation.Degrees000);
                pSetValid.SetPlotType(pSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Limits);
                pSetValid.SetUseStandardScale(pSet, true);
                pSetValid.SetStdScaleType(pSet, StdScaleType.StdScale3To8InchIs1ft);
                pSetValid.SetZoomToPaperOnUpdate(pSet, false);
                // pSetValid.SetDefaultPlotConfig(pSet);
                // apply setting overrides to plot info
                pInfo.OverrideSettings = pSet;
               
                PlotInfoValidator pInfoValid = new PlotInfoValidator();
                pInfoValid.Validate(pInfo);

                // Settings are set - attempt plot
                pEng.BeginPlot(pProgDialog, parms);
                pEng.BeginDocument(pInfo, fullDWGPath, parms, Copies, false, string.Empty);
                pEng.BeginPage(pPInfo, pInfo, true, parms);
                pEng.BeginGenerateGraphics(parms);
                pEng.EndGenerateGraphics(parms);
                pEng.EndPage(parms);
                pEng.EndDocument(parms);
                pEng.EndPlot(parms);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.TargetSite + "\n" + e.StackTrace);
            }
            finally
            {
                pEng.Destroy();
            }
        }
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Glenn R

  • Guest
Re: PlottingServices help
« Reply #1 on: December 06, 2006, 04:27:13 PM »
There is an example (C++) in the ARX docs - you should be to translate it to C# easily enough.

Hope this helps.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #2 on: December 06, 2006, 06:07:26 PM »
I have looked over the C++ example and it wasn't much help.
I don't know C++ so the translation is not easy.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PlottingServices help
« Reply #3 on: December 06, 2006, 07:11:49 PM »
Mark, what is the actual error you are getting ... if you get an error ?


I haven't tried the code 'cause I'd have to change a lot to get it to suit my conditions
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: PlottingServices help
« Reply #4 on: December 06, 2006, 07:23:09 PM »
There is an example (C++) in the ARX docs - you should be to translate it to C# easily enough.

Hope this helps.

I recall a help from you... and now I want to share that...

Just replace the "->" with "." and that's all......

HTH
he he

Sorry, couldn't resist....

Glenn R

  • Guest
Re: PlottingServices help
« Reply #5 on: December 06, 2006, 07:49:10 PM »
I know it sounds funny, but that's essentially it.
I initially designed mine around that sample. The function calls are pretty much the same names from C++ to C#.

Draftek

  • Guest
Re: PlottingServices help
« Reply #6 on: December 06, 2006, 08:26:31 PM »
I remember having trouble with plotting, something about background plotting being enabled. I'll take a look when I get back to the office tomorrow....

Glenn R

  • Guest
Re: PlottingServices help
« Reply #7 on: December 06, 2006, 08:49:07 PM »
Yes - definately set "BACKGROUNDPLOT" to 0 to disable it.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PlottingServices help
« Reply #8 on: December 07, 2006, 12:41:36 AM »
Wow !  I've just spent a couple of hours playing with PlottingServices and namespaces associated with plotting.

That is one area that could do with a book being written about it.

The PlotSettingsValidator alone would be a couple of chapters

LayoutManager
PlotSettings
PlotInfo

LocaleMediaName and canonicalMediaNameList and plotDeviceList and GetPlotStyleSheetList

PlotEngine
PlotInfoValidator
MatchingPolicy
PlotPageInfo

... then a chapter on exceptions

... anyone want to finance me for about 8 weeks or so  ? :-)





kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: PlottingServices help
« Reply #9 on: December 07, 2006, 12:52:38 AM »
I agree wholeheartedly Kerry - plotting in ARX/.NET is a black art at best.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PlottingServices help
« Reply #10 on: December 07, 2006, 01:14:25 AM »
Mark,

This line :
string plotDeviceName = "WPI-8830-Full.pc3";
can you check it .. should it should be the Plotter name, not the pc3 ? ?


added:
Looks like it can be either .. perhaps treat me with ignore   ;-)

give something like this a run ..
Code: [Select]
        [CommandMethod("GPDN")]
        static public void GetPlotDeviceNames()
        {   
            /// requires the COM interface
            /// Autodesk.AutoCAD.Interop
            ///
            AcadApplication acadApp = (AcadApplication)AcadApp.AcadApplication;

            AcadLayout activeLayout = acadApp.ActiveDocument.ActiveLayout;

            Object plotDevices = activeLayout.GetPlotDeviceNames();
           
            Array  deviceArray = (Array)plotDevices;

            foreach (string deviceName in deviceArray)
            {
                /// requires Autodesk.AutoCAD.Windows.Forms
                MessageBox.Show("plot device name is: " + deviceName);
            }
        }
« Last Edit: December 07, 2006, 02:03:14 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PlottingServices help
« Reply #11 on: December 07, 2006, 02:29:19 AM »
Yep, can be either ...
At least thats how it looks ..


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PlottingServices help
« Reply #12 on: December 07, 2006, 03:59:34 AM »
.....

That is one area that could do with a book being written about it.

............

On reflection, the first 2 chapters should be on ' Definition of Terms ' stuff ..

.. but that's booring so it would have to go in the back    :lmao:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #13 on: December 07, 2006, 10:44:36 AM »
My code breaks at the line:
pInfoValid.Validate(pInfo);

I read in the ARX docs that ALL the properties of the plotinfo object need to be filled or there will be an error.
Can anyone explain how to copy an existing PlotInfo object into a new one?

I will try replacing -> with . in the C++ code. My hopes are not high.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Draftek

  • Guest
Re: PlottingServices help
« Reply #14 on: December 07, 2006, 11:15:53 AM »
Try adding this instead:

Code: [Select]
PlotInfoValidator validator = new PlotInfoValidator();
validator.MediaMatchingPolicy = Autodesk.AutoCAD.PlottingServices.MatchingPolicy.MatchEnabled;

before calling the validate method

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #15 on: December 07, 2006, 11:25:47 AM »
Thanks for the suggestion.
Unfortunately I tried it but got the same error.

---------------------------
Void Check(Int32)
   at Autodesk.AutoCAD.Runtime.Interop.Check(Int32 returnValue)

   at Autodesk.AutoCAD.PlottingServices.PlotInfoValidator.Validate(PlotInfo info)

   at PlotNET.PlotterClass.NETPlot() in M:\Programming\Projects\ACAD_Development\PlotNET\PlotNET\Class.cs:line 106
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #16 on: December 07, 2006, 05:26:58 PM »
forgot this:
pInfo.Layout = LayoutManager.Current.GetLayoutId("Model");

 :ugly:

P.S. - If you are a VB programmer that is just getting your head around C# and someone says that you can convert C++ code to C# if you "just change -> to ." it is good to remember that the person making the suggestion knows both C++ and C# whereas you don't. Unless you know C++ you will likely hurt your brain when attempting such a maneuver, possibly bashing it into a ::.
« Last Edit: December 07, 2006, 05:33:00 PM by mohnston »
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

LE

  • Guest
Re: PlottingServices help
« Reply #17 on: December 07, 2006, 05:39:22 PM »
I am moving into C#, and have been able to port most of my code in C++/ARX to C#, but not by simple replacing the -> for . - it requires more than that, at least for me... (I even have been able to port VB to C# - and it is much easier - but I do not know much about VB)

What, sample in the SDK are you porting?

Glenn R

  • Guest
Re: PlottingServices help
« Reply #18 on: December 07, 2006, 07:03:00 PM »
Mark, have you gotten it to work or would you like and example of how to use a pagesetup...that's the way I do it.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #19 on: December 08, 2006, 11:15:46 AM »
What, sample in the SDK are you porting?

I was really just trying to understand the plotting code.
What ended up helping me was porting from a script file to C#.
That showed me I was missing the Layout.

Glenn,
I do have something working but I would really appreciate an example of using pagesetup since that was my first inclination.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #20 on: December 08, 2006, 12:06:22 PM »
Maybe this will help someone since there really isn't very much in the way of documentation on the PlottingServices.

Code: [Select]
        [CommandMethod("CSharpPlot")]
        static public void CSharpPlot()
        {
            // Set up some variables
            string fullDWGPath = @"C:\PlotTestFile.dwg";
            Document ThisDrawing = Application.DocumentManager.Open(fullDWGPath, true);
            Database ThisDB = ThisDrawing.Database;
            int Copies = 1;
            Object parms = null;
            string plotDeviceName = "myValidPlotDevice.pc3";
            string styleSheet = "myValidStyleSheet.ctb";

            Point2d originPoint = new Point2d(0, 0);
            // Set up some PLOT specific variables
            PlotInfo pInfo = new PlotInfo();
            pInfo.Layout = LayoutManager.Current.GetLayoutId("Model");

            PlotSettings pSet = new PlotSettings(true);
            PlotSettingsValidator pSetValid = PlotSettingsValidator.Current;

            PlotPageInfo pPInfo = new PlotPageInfo();
            PlotConfigManager.SetCurrentConfig(plotDeviceName);
            PlotConfigManager.RefreshList(RefreshCode.All);
            // set the Canonical Media Name (paper name) - for sample purposes just grab the first one
            StringCollection cMNs = PlotConfigManager.CurrentConfig.CanonicalMediaNames;
            string mediaName = cMNs[0].ToString();

            try
            {
                pSetValid.SetPlotConfigurationName(pSet, plotDeviceName, mediaName);
                // It was recommended to refresh lists before changing settings
                pSetValid.RefreshLists(pSet);

                pSetValid.SetCurrentStyleSheet(pSet, styleSheet);
                pSetValid.SetPlotCentered(pSet, false);
                pSetValid.SetPlotOrigin(pSet, originPoint);
                pSetValid.SetPlotPaperUnits(pSet, PlotPaperUnit.Inches);
                pSetValid.SetPlotRotation(pSet, PlotRotation.Degrees000);
                pSetValid.SetPlotType(pSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Limits);
                pSetValid.SetUseStandardScale(pSet, true);
                pSetValid.SetStdScaleType(pSet, StdScaleType.StdScale3To8InchIs1ft);
                pSetValid.SetZoomToPaperOnUpdate(pSet, false);

                // apply setting overrides to plot info
                pInfo.OverrideSettings = pSet;
                PlotInfoValidator pInfoValid = new PlotInfoValidator();
                pInfoValid.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                pInfoValid.Validate(pInfo);

                // Settings are set - attempt plot
                PlotProgressDialog pProgDialog = new PlotProgressDialog(false, 1, true);
                //PlotProgressDialog pProgDialog = new PlotProgressDialog(true, 1, true); // In case it's a preview
                pProgDialog.OnBeginPlot();
                pProgDialog.IsVisible = true;
                PlotEngine pEng = PlotFactory.CreatePublishEngine();
                //PlotEngine pEng = PlotFactory.CreatePreviewEngine(1); // In case it's a preview
                pEng.BeginPlot(pProgDialog, parms);

                pEng.BeginDocument(pInfo, fullDWGPath, parms, Copies, false, string.Empty);
                // pEng.BeginDocument(pInfo, fullDWGPath, parms, Copies, true, fullPLTPath); // In case plot to file
                pEng.BeginPage(pPInfo, pInfo, true, parms);
                pEng.BeginGenerateGraphics(parms);
                pEng.EndGenerateGraphics(parms);
                pEng.EndPage(parms);
                pEng.EndDocument(parms);
                pEng.EndPlot(parms);
                pProgDialog.OnEndPlot();
                pProgDialog.Destroy();
                pEng.Destroy();
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.TargetSite + "\n" + e.StackTrace);
            }

        }
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

smcclure

  • Guest
Re: PlottingServices help
« Reply #21 on: January 09, 2007, 03:45:16 PM »
Are you using 2007? I had some plot code that worked just fine in 2005, and completely bombs in 2007 (causes a fatal exception and corrupts the current profile....) Has anyone experienced similar trouble with 2007 for plotting compared to previous versions?

 - Scott

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: PlottingServices help
« Reply #22 on: January 09, 2007, 08:08:55 PM »
Are you using 2007? I had some plot code that worked just fine in 2005, and completely bombs in 2007 (causes a fatal exception and corrupts the current profile....) Has anyone experienced similar trouble with 2007 for plotting compared to previous versions?

 - Scott

AutoCAD 2007
VS 2005
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: PlottingServices help
« Reply #23 on: July 31, 2009, 01:23:32 PM »
So has anybody updated plotting for 2010 yet?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: PlottingServices help
« Reply #24 on: July 31, 2009, 04:10:17 PM »
I copied this from Kean W (Through the Interface) and made changes to plot to my machine.  Seems really really slow though
Code: [Select]
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.PlottingServices;

namespace PlottingApplication
{

    public class PlottingCommands
    {

        [CommandMethod("simplot")]
        static public void SimplePlot()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                // We'll be plotting the current layout
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, 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;
                // We'll plot the extents, centered and
                // scaled to fit
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                psv.SetUseStandardScale(ps, true);
                //psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
                psv.SetPlotCentered(ps, true);
                // We'll use the standard DWF PC3, as
                // for today we're just plotting to file
                psv.SetPlotConfigurationName(ps, "2010 Oce.pc3", "ARCH_expand_D_(36.00_x_24.00_Inches)");
                //psv.SetPlotConfigurationName(ps, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
                // We need to link the PlotInfo to the
                // PlotSettings and then validate it
                pi.OverrideSettings = ps;
                PlotInfoValidator piv = new PlotInfoValidator();
                piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                piv.Validate(pi);
                // A PlotEngine does the actual plotting
                // (can also create one for Preview)
                if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                {
                    PlotEngine pe = PlotFactory.CreatePublishEngine();
                    using (pe)
                    {
                        // Create a Progress Dialog to provide info
                        // and allow thej user to cancel
                        PlotProgressDialog ppd = new PlotProgressDialog(false, 1, true);
                        using (ppd)
                        {
                            ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress");
                            ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
                            ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
                            ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
                            ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
                            ppd.LowerPlotProgressRange = 0;
                            ppd.UpperPlotProgressRange = 100;
                            ppd.PlotProgressPos = 0;
                            // Let's start the plot, at last
                            ppd.OnBeginPlot();
                            ppd.IsVisible = true;
                            pe.BeginPlot(ppd, null);
                            // We'll be plotting a single document
                            pe.BeginDocument(
                                 pi,
                                  doc.Name,
                                   null,
                                    1,
                                    false,
                                //true, // Let's plot to file
                                      "c:\\test-output"
                                       );
                            // Which contains a single sheet
                            ppd.OnBeginSheet();
                            ppd.LowerSheetProgressRange = 0;
                            ppd.UpperSheetProgressRange = 100;
                            ppd.SheetProgressPos = 0;
                            PlotPageInfo ppi = new PlotPageInfo();
                            pe.BeginPage(
                                 ppi,
                                  pi,
                                   true,
                                    null
                                     );
                            pe.BeginGenerateGraphics(null);
                            pe.EndGenerateGraphics(null);
                            // Finish the sheet
                            pe.EndPage(null);
                            ppd.SheetProgressPos = 100;
                            ppd.OnEndSheet();
                            // Finish the document
                            pe.EndDocument(null);
                            // And finish the plot
                            ppd.PlotProgressPos = 100;
                            ppd.OnEndPlot();
                            pe.EndPlot(null);
                        }
                    }
                }
                else
                {
                    ed.WriteMessage(
                         "\nAnother plot is in progress."
                          );
                }
            }
        }
    }
}
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

wannabe

  • Guest
Re: PlottingServices help
« Reply #25 on: August 01, 2009, 05:47:01 AM »
Have you checked out the .NET Developers guide? :wink:

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: PlottingServices help
« Reply #26 on: August 02, 2009, 03:22:41 PM »
I did check the developers guide, and found a similiar post of code.  I did find that I "thought" I had disabled background plotting, but had not, which is why it seemed so slow
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)