Community
Dear All,
Let me know code reference for the dwg to pdf plot with C#.
I got error with below code.
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.PlottingServices; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.AutoCAD.Geometry; using System.IO; using Autodesk.AutoCAD.EditorInput; namespace PrintPDF { public class Class1 { [CommandMethod("eden",CommandFlags.Session)] public static void printpdf() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { LayoutManager layoutMgr = LayoutManager.Current; layoutMgr.CurrentLayout = "TSLayout"; BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead); Layout lo = (Layout)tr.GetObject( btr.LayoutId, OpenMode.ForRead); PlotInfo pi = new PlotInfo(); pi.Layout = btr.LayoutId; PlotSettings ps = new PlotSettings(lo.ModelType); ps.CopyFrom(lo); PlotSettingsValidator psv = PlotSettingsValidator.Current; psv.SetPlotType( ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout); psv.SetUseStandardScale(ps, true); psv.SetStdScaleType(ps, StdScaleType.StdScale1To1); psv.SetPlotCentered(ps, true); psv.SetPlotConfigurationName(ps,"DWG To PDF.pc3", "ISO A1(841.00 x 594.00 MM)"); pi.OverrideSettings = ps; PlotInfoValidator piv = new PlotInfoValidator(); piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled; piv.Validate(pi); if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting) { using (PlotEngine pe = PlotFactory.CreatePublishEngine()) { using (PlotProgressDialog ppd = new PlotProgressDialog(false, 1, true)) { 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, // Let's plot to file "c:\\test-output" ); // 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."); } } } } }
Solved! Go to Solution.
Solved by SENL1362. Go to Solution.
One cannot Plot a Layout Area Centered, i.e. the combination of Layout and Centered is not allowed.
psv.SetPlotType( ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout); psv.SetUseStandardScale(ps, true); psv.SetStdScaleType(ps, StdScaleType.StdScale1To1); psv.SetPlotCentered(ps, true);
As an alternative u can use PlotArea Extents.
Can't find what you're looking for? Ask the community or share your knowledge.