Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void printDWG(string dwg, string rev)
- {
- using (Database db = new Database(false, true))
- {
- // Open a database transaction for the drawing
- db.ReadDwgFile(dwg, FileShare.ReadWrite, false, null);
- // Use the transaction to gather data
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- // 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.Window);
- psv.SetPlotWindowArea(ps, new Extents2d(new Point2d(0.01625, 0.01625), new Point2d(41.9375, 29.9375)));
- psv.SetUseStandardScale(ps, true);
- psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
- 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", "ARCH_E1_(30.00_x_42.00_Inches)");
- psv.SetPlotPaperUnits(ps, PlotPaperUnit.Inches);
- psv.SetPlotRotation(ps, PlotRotation.Degrees090);
- psv.RefreshLists(ps);
- psv.SetCurrentStyleSheet(ps, "Stellar FullSize Mono.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 the 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,
- dwg,
- 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
- {
- // Show this message
- MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment