DWG to PDF (Plotting a DWG model)

DWG to PDF (Plotting a DWG model)

Drew.GarciaUZTB3
Participant Participant
794 Views
4 Replies
Message 1 of 5

DWG to PDF (Plotting a DWG model)

Drew.GarciaUZTB3
Participant
Participant

Hi I'm a beginner in coding, I'm seeking some assistance on how to fix the code below. I'm currently getting errors during part ( plotSettingValidator.SetPlotConfigurationName(plotPositon, "DWG PDF.pc3", "ISO A1(841.00 x 594.00 MM)");. 

 

I have a feeling it's something to do with the part (...,"DWG PDF.pc3"..).

 

 [CommandMethod("simplot")]
            static public void SimplePlot()

            {
                Document activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument;
                Editor documentEditor = activeDocument.Editor;

                Database fileData = activeDocument.Database;
                Transaction dwgFileInfo = fileData.TransactionManager.StartTransaction();

                using (dwgFileInfo)

                {
                    // Plotting the current layout
                    BlockTableRecord blockTableRecord = (BlockTableRecord)dwgFileInfo.GetObject(fileData.CurrentSpaceId, OpenMode.ForRead);
                    Layout layout = (Layout)dwgFileInfo.GetObject(blockTableRecord.LayoutId, OpenMode.ForRead); ;
                    PlotInfo plotInfo = new PlotInfo();

                    plotInfo.Layout = blockTableRecord.LayoutId;

                    PlotSettings plotPositon = new PlotSettings(layout.ModelType);
                    PlotSettingsValidator plotSettingValidator = PlotSettingsValidator.Current;
                    plotPositon.CopyFrom(layout);

                    //Layout of the plot with default settings 
                    plotSettingValidator.SetPlotType(plotPositon, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                    plotSettingValidator.SetUseStandardScale(plotPositon, true);
                    plotSettingValidator.SetStdScaleType(plotPositon, StdScaleType.StdScale1To1);
                    //plotSettingValidator.SetPlotCentered(plotPositon, true);
              
                    //plotSettingValidator.SetPlotConfigurationName(plotPositon, @"\\print\Pepe V2", "A4");
                    plotSettingValidator.SetPlotConfigurationName(plotPositon, "DWG PDF.pc3", "ISO A1(841.00 x 594.00 MM)");
                
                    plotInfo.OverrideSettings = plotPositon;
                    PlotInfoValidator plotInfoValidator = new PlotInfoValidator();
                    plotInfoValidator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                    plotInfoValidator.Validate(plotInfo);

                    if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                    {
                        PlotEngine plotEnginge = PlotFactory.CreatePublishEngine();
                        using (plotEnginge)
                        {
                            // Create a Progress Dialog to provide info and allow the user to cancel
                            PlotProgressDialog dialogPlot = new PlotProgressDialog(false, 1, true);
                            using (dialogPlot)
                            {
                                dialogPlot.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress");
                                dialogPlot.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
                                dialogPlot.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
                                dialogPlot.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
                                dialogPlot.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
                                dialogPlot.LowerPlotProgressRange = 0;
                                dialogPlot.UpperPlotProgressRange = 100;
                                dialogPlot.PlotProgressPos = 0;

                                // Starting Plot scenario
                                dialogPlot.OnBeginPlot();
                                dialogPlot.IsVisible = true;
                                plotEnginge.BeginPlot(dialogPlot, null);

                                // We'll be plotting a single document
                                plotEnginge.BeginDocument(plotInfo, activeDocument.Name, null, 1, true, @"\\fileserver\users\drew.garcia\Desktop\Dummy Folder\DWG Test Files\Drawing1.dwg");

                                // Which contains a single sheet
                                dialogPlot.OnBeginSheet();
                                dialogPlot.LowerSheetProgressRange = 0;
                                dialogPlot.UpperSheetProgressRange = 100;
                                dialogPlot.SheetProgressPos = 0;

                                PlotPageInfo pageInfo = new PlotPageInfo();

                                plotEnginge.BeginPage(pageInfo, plotInfo, true, null);
                                plotEnginge.BeginGenerateGraphics(null);
                                plotEnginge.EndGenerateGraphics(null);

                                // Finish the sheet
                                plotEnginge.EndPage(null);
                                dialogPlot.SheetProgressPos = 100;
                                dialogPlot.OnEndSheet();

                                // Finish the document
                                plotEnginge.EndDocument(null);

                                // And finish the plot
                                dialogPlot.PlotProgressPos = 100;
                                dialogPlot.OnEndPlot();
                                plotEnginge.EndPlot(null);
                            }
                        }
                    }
                    else
                    {
                        documentEditor.WriteMessage("\nAnother plot is in progress.");
                    }

                }
            }       

 

 

0 Likes
Accepted solutions (1)
795 Views
4 Replies
Replies (4)
Message 2 of 5

Drew.GarciaUZTB3
Participant
Participant

DrewGarciaUZTB3_0-1656464620409.png

That's the error that keeps showing up. 

0 Likes
Message 3 of 5

norman.yuan
Mentor
Mentor
Accepted solution

In the method SetPlotConfigurationName(), the third argument should be CanonicalMediaName, not the media name you see in the "Paper size" dropdown list of the plot dialog, which is LocaleMediaName.

 

You can find out CononicalMediaName corresponding to a known LocaleMediaName by using PlotConfig's CononicalMediaNames property and GetLocalMediaName([cononicalMediaName]) method.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 5

Drew.GarciaUZTB3
Participant
Participant

DrewGarciaUZTB3_0-1656467514603.png

@norman.yuan thanks for quick response, but I'm still getting the same error

0 Likes
Message 5 of 5

norman.yuan
Mentor
Mentor

Are you sure for the plot device "Dwg to Pdf.pc3" has a paper size defined with "Microsoft Print to PDF" as CanonicalMeadiaName?

 

Where did you get your "DWG to PDF.pc3"? It is totally not possible a paper size with such a CanonicalMediaName. For the paper size "ISO A1(841.00 x 594.00 MM)" (LocaleMediaName) from "DWG to PDF.pc3", the corresponding CanonicalMediaName is "ISO_A1_(841.00_x_594.00_MM)". As my previous reply said, you need to learn how to find out CanonicalMediaName/LocaleMediaName using PlotConfig class.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes