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

Reg. Plotting To PDF

9 REPLIES 9
Reply
Message 1 of 10
dhimant.bhensdadia
1034 Views, 9 Replies

Reg. Plotting To PDF

Hi,

 

Can anyone tell me that how to plot the dwg into pdf file using .net api in autocad that can convert my dwg to pdf and save it to user defined location ?

9 REPLIES 9
Message 2 of 10

Hi,

 

how far did you come with your tries? And what is the step you got troubles? Show the code and someone will help you.

 

If it's just "can I get the code" then look >>>here<<<, there are so many samples you can start with, so it does not make sense to start every day a thread showing how to plot (plot to "PDF to DWG.pc3" in your case).

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 10
rom1_am
in reply to: Alfred.NESWADBA

Hi,

 

You're totally right Alfred. But besides that, when we see how many people ask help on this topic of plotting PDF, Autodesk should ask themselves the good questions and do something easy and efficient in order to publish in pdf (I mean in the functionnalities of the .Net API).

We've already made some code to generate PDF for our work with help from forums, but I found that it's really complicated to program for such a basic need, and we still meet problems of stability with this code.

 

Thanks

Message 4 of 10
Alfred.NESWADBA
in reply to: rom1_am

Hi,

 

>> but I found that it's really complicated to program for such a basic need

To be honest, if you look to the mass of questions about plotting in this forum (just plotting, not development of plot-routines) you can see that it is not easy at all, settings of layouts, settings of viewports, scaling, all details in plot-dialog ... at least no functionality with a lot of flexibility can be coded in just a few lines.

 

Anyway, you are right too with "the .NET api for plotting is quite complex", but as it's adding a lot of flexibility within the functions/methods, you have more options compared to LISP, COM, script. If you don't need that plus of functions/methods you might go the way through COM as this means less lines, easier to debug also.

 

>> Autodesk should ask themselves the good questions and do something easy and efficient

You can use LISP, COM, script if you need easy ways (with less flexibility).

 

>> we still meet problems of stability with this code

Can you describe the issues and show the code that brings them up?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 10

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.SetPlotCentered(ps, true);

                // We'll use the standard DWF PC3, as
                // for today we're just plotting to file

                psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", "ANSI_A_(8.50_x_11.00_Inches)");

                psv.SetCurrentStyleSheet(ps, "monochrome.ctb");

                // 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, true, "D:\\Temp\\" + fileName);
                            string saveName = @"D:\Temp\Test" + ii.ToString();
                            pe.BeginDocument(pi, doc.Name, null, 1, true, saveName);
                            //pe.BeginDocument(pi, doc.Name, null, 1, true, "D:\\Temp\\Test-Taklu");

                            // 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.");
                }

 

=============================

 

Error : As shown in the above code I have added 1 line highlighted in red color becuase without it, the drawing was converted into pdf with colored.

 

When I have execute this code for 1 drawing it works fine, but when I am going to execute for more than 1 files, I am getting the error named 

 

"eInvalidInput" at the highlighted line. Can any one please suggest me what should I do ?

 

My task is plotting to pdf in Balck N White not in colored.

Message 6 of 10

Hi,

 

have not tried your code, but what comes to my mind first was: close the transaction earlier, holding an active transaction open through the complete plotting-managment (that is not transaction-based at all) might be one unnecessary obstacle.

 

Otherwise .. have you tried the COM approach (e.g. >>>this/click<<<)?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 10
rom1_am
in reply to: Alfred.NESWADBA

Hi,

 

Actually, thanks this post, i've worked again on this topic, and i think i've found our problem. Our code works well (it's just a mix of different examples found on this site, it uses the creation of a dsd file. Edit: our code is approximately an adaptation of this one: http://adndevblog.typepad.com/autocad/2012/05/how-to-use-autodeskautocadpublishingpublisherpublishex... ).

 

The problem seems to come from the loading of the pc3 files: we've made a customized 'dwg to pdf.pc3' file which works well when we stay in an AutoCAD profile, but it doesn't work correctly each time we change of profile (wheras the support path is correct in each profile). So I have the impression that the pc3 file is not loaded correctly when we change of profile.

I've asked our drawers to close completely and reopen AutoCAD each time they activate a new profile, but is there a way to force the correct loading of the pc3 file by programmation?

 

Thank you

Message 8 of 10

HI, Can you check the System variable 'BACKGROUNDPLOT'. If it is set to 1 or 3 then it might create this Kind of Problem.
Message 9 of 10
SENL1362
in reply to: rom1_am

I've nothished that too and therefore tried this without any luck:
PlotConfigManager.RefreshList(RefreshCode.RefreshSystemDevicesList);

Currently w'll copy the PC3 and PMP into place before calling the plot routines. However changing the absolute path of the PMP might cause another problem.


Message 10 of 10
rom1_am
in reply to: SENL1362

Hello

 

Concerning 'BACKGROUNDPLOT', I set it to 0 by programmation.

 

Also, I've added this 2 lines of code:

 

PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;
PlotConfigManager.RefreshList(RefreshCode.All);

 

Need to be tested some days.

 

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