Author Topic: PlottingServices help  (Read 11271 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