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

"Error:Invalid Input" occurs while making PDF file (Object ARX, C#)

2 REPLIES 2
Reply
Message 1 of 3
Daikichi
1496 Views, 2 Replies

"Error:Invalid Input" occurs while making PDF file (Object ARX, C#)

Hey Everyone,

 

I'd like to make 'PDF' files from 'DWF' AutoCAD files.

 

Therefore, I referred the official "AutoCAD .NET Developer Guide".

 

It has a sample code below.   I tried this code.

 

However, an error has occured at the last part of this code, "acPlEng.EndPlot(null);".

 

Error shows "Error:Invalid Input";

 

I drew just one simple circle, and then put "PlotCurrentLayout" command.

 

Here's sample code.   Sorry to be lengthy.
--------------------------------------------------------------------------
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
 
[CommandMethod("PlotCurrentLayout")]
public static void PlotCurrentLayout()
{
  // Get the current document and database, and start a transaction
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  Database acCurDb = acDoc.Database;
 
  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  {
      // Reference the Layout Manager
      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, "DWF6 ePlot.pc3",
                                          "ANSI_A_(8.50_x_11.00_Inches)");
 
      // 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,
                                        "c:\\myplot");
 
                  // 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);
                  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);   // <---  "Error:Invalid Input" occurs.
              }
          }
      }
  }
}
--------------------------------------------------------------------------

 

I'm developing with Visual Studio 2010 (C#) and Object ARX.

 

Any advice would be greatly appreciated.

2 REPLIES 2
Message 2 of 3
JamieVJohnson2
in reply to: Daikichi

this is happening here because, none of the actual plot processing is taking place until you call end plot.  Then it reads all theinput data you fed it and has a cow with something.  I've run into this way back in VBA.  Check all the parameters you feed into it.  It could be bad file name, bad printer name, bad location, bad layout name.  Something of the like.

 

jvj

jvj
Message 3 of 3
Daikichi
in reply to: JamieVJohnson2

Hi, JamieVJohnson2.

 

Thank you for your answering.

 

I struggled to resolve this prob, so I  reffered other sample codes in this web site.

 

Here is it's link.

 

http://through-the-interface.typepad.com/through_the_interface/

 

famaous site for developing applications regarding AutoCAD with Object ARX.

 

Thanks a lot.

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