PLoting PDF error, xternal component has thrown an exception and ePageCancelled

PLoting PDF error, xternal component has thrown an exception and ePageCancelled

Anonymous
Not applicable
824 Views
1 Reply
Message 1 of 2

PLoting PDF error, xternal component has thrown an exception and ePageCancelled

Anonymous
Not applicable

Hi there 

I used some code from the following sources to do a batch plotting function that iterates over several drawings and plots the Model view

 

http://docs.autodesk.com/ACD/2011/ENU/filesMDG/WS1a9193826455f5ff2566ffd511ff6f8c7ca-33b0.htm

https://adndevblog.typepad.com/autocad/2012/06/backgroundplot-system-variable.html

https://through-the-interface.typepad.com/through_the_interface/2007/10/allowing-select.html

 

And this error occurs on a user environment.

[Error 1]

Exception: External component has thrown an exception.
StackTrace: at Autodesk.AutoCAD.PlottingServices.PlotEngine.BeginGenerateGraphics(Object parameters)

[Error 1]

ePageCancelled
StackTrace: at Autodesk.AutoCAD.PlottingServices.PlotEngine.BeginGenerateGraphics(Object parameters)

 

In my environment the code works fine but my plot device and media name are different from the user.

Also the user path to save the pdf is in a network drive (Not sure if is relevant, but the user also needed some admin permission to install this plugin).

Also notice that I added the  lines because I wasn't able to plot more than one drawing.

short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");
//set the BACKGROUNDPLOT = 0 temporarily.
Application.SetSystemVariable("BACKGROUNDPLOT", 0);

//PLOT code here

Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);

 

 using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");

                    //set the BACKGROUNDPLOT = 0 temporarily.

                    Application.SetSystemVariable("BACKGROUNDPLOT", 0);

                    // Reference the Layout Manager
                    string pdfName = Path.Combine(HorizantTool.Default.PdfPath, $"{Path.GetFileNameWithoutExtension(acDoc.Name)}.pdf");
                    result.AddDebug($"PDF Name: {pdfName}");
                    LayoutManager acLayoutMgr;
                    acLayoutMgr = LayoutManager.Current;
                    // Get the current layout and output its name in the Command Line window
                    Layout acLayout;
                    acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout),
                                                       OpenMode.ForRead) as Layout;
                    // Get the PlotInfo from the layout
                    PlotInfo acPlInfo = new PlotInfo();
                    acPlInfo.Layout = acLayout.ObjectId;

                    // Get a copy of the PlotSettings from the layout
                    PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
                    acPlSet.CopyFrom(acLayout);

                    // Update the PlotSettings object
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    // Set the plot type
                    acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                    // Set the plot scale
                    acPlSetVdr.SetUseStandardScale(acPlSet, true);
                    acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
                    // Center the plot
                    acPlSetVdr.SetPlotCentered(acPlSet, true);
                    // Set the plot device to use

                    //acPlSetVdr.SetPlotConfigurationName(acPlSet, HorizantTool.Default.PlotDeviceName,HorizantTool.Default.PlotMediaName);
                    acPlSetVdr.SetPlotConfigurationName(acPlSet, HorizantTool.Default.PlotDeviceName, HorizantTool.Default.PlotMediaName);
                    acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters);
                    acPlSetVdr.SetPlotOrigin(acPlSet, new Point2d(-0.17, -1.17));
                    acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090);//Landscape

                    // Set the plot info as an override since it will
                    // not be saved back to the layout
                    acPlInfo.OverrideSettings = acPlSet;
                    // Validate the plot info
                    PlotInfoValidator acPlInfoVdr = new PlotInfoValidator();
                    acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                    acPlInfoVdr.Validate(acPlInfo);
                    // Check to see if a plot is already in progress
                    if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                    {
                        using (PlotEngine acPlEng = PlotFactory.CreatePublishEngine())
                        {
                            // Track the plot progress with a Progress dialog
                            PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false,
                                                                                    1,
                                                                                    true);
                            using (acPlProgDlg)
                            {
                                // Define the status messages to display when plotting starts
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle,
                                                              "Plot Progress");
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage,
                                                              "Cancel Job");
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage,
                                                              "Cancel Sheet");
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption,
                                                              "Sheet Set Progress");
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption,
                                                              "Sheet Progress");
                                // Set the plot progress range
                                acPlProgDlg.LowerPlotProgressRange = 0;
                                acPlProgDlg.UpperPlotProgressRange = 100;
                                acPlProgDlg.PlotProgressPos = 0;
                                // Display the Progress dialog
                                acPlProgDlg.OnBeginPlot();
                                acPlProgDlg.IsVisible = true;
                                // Start to plot the layout
                                acPlEng.BeginPlot(acPlProgDlg, null);
                                // Define the plot output
                                acPlEng.BeginDocument(acPlInfo,
                                                      acDoc.Name,
                                                      null,
                                                      1,
                                                      true,
                                                      pdfName);
                                // Display information about the current plot
                                acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status,
                                                              "Plotting: " + acDoc.Name + " - " +
                                                              acLayout.LayoutName);
                                // Set the sheet progress range
                                acPlProgDlg.OnBeginSheet();
                                acPlProgDlg.LowerSheetProgressRange = 0;
                                acPlProgDlg.UpperSheetProgressRange = 100;
                                acPlProgDlg.SheetProgressPos = 0;
                                // Plot the first sheet/layout
                                PlotPageInfo acPlPageInfo = new PlotPageInfo();
                                acPlEng.BeginPage(acPlPageInfo,
                                                  acPlInfo,
                                                  true,
                                                  null);
                                acPlEng.BeginGenerateGraphics(null); ---->ERROR OCCURS HERE
                                acPlEng.EndGenerateGraphics(null);
                                // Finish plotting the sheet/layout
                                acPlEng.EndPage(null);
                                acPlProgDlg.SheetProgressPos = 100;
                                acPlProgDlg.OnEndSheet();
                                // Finish plotting the document
                                acPlEng.EndDocument(null);
                                // Finish the plot
                                acPlProgDlg.PlotProgressPos = 100;
                                acPlProgDlg.OnEndPlot();
                                acPlEng.EndPlot(null);
                            }
                        }
                    }

                    Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
                }

 

Any idea what can be causeing this error?

Could be permissions on the location where the PDF is going to be generated?

Or is something related to the plot device and media name ??

 

Those are the only main differences that identified between mine and the other user environment.

 

Thanks in advance for the help.

 

 

 

0 Likes
Accepted solutions (1)
825 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

The issue was the pdf destination path. I was defining a path in a settings file but it wasn't being reloaded after changing it.

Just added a few more validations to ensure the path existed and that fixed it.

 

 

0 Likes