Author Topic: PlottingServices help  (Read 11270 times)

0 Members and 1 Guest are viewing this topic.

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)