Guest User

Untitled

a guest
Oct 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.75 KB | None | 0 0
  1.        public static void printDWG(string dwg, string rev)
  2.         {
  3.             using (Database db = new Database(false, true))
  4.             {
  5.                 // Open a database transaction for the drawing
  6.                 db.ReadDwgFile(dwg, FileShare.ReadWrite, false, null);
  7.                 // Use the transaction to gather data
  8.                 using (Transaction tr = db.TransactionManager.StartTransaction())
  9.                 {
  10.  
  11.                     // We'll be plotting the current layout
  12.                     BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
  13.                     Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
  14.  
  15.  
  16.                     // We need a PlotInfo object linked to the layout
  17.                     PlotInfo pi = new PlotInfo();
  18.                     pi.Layout = btr.LayoutId;
  19.  
  20.  
  21.                     // We need a PlotSettings object based on the layout settings which we then customize
  22.                     PlotSettings ps = new PlotSettings(lo.ModelType);
  23.                     ps.CopyFrom(lo);
  24.  
  25.  
  26.                     // The PlotSettingsValidator helps create a valid PlotSettings object
  27.                     PlotSettingsValidator psv = PlotSettingsValidator.Current;
  28.  
  29.  
  30.                     // We'll plot the extents, centered and scaled to fit
  31.                     psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
  32.                     psv.SetPlotWindowArea(ps, new Extents2d(new Point2d(0.01625, 0.01625), new Point2d(41.9375, 29.9375)));
  33.                     psv.SetUseStandardScale(ps, true);
  34.                     psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
  35.                     psv.SetPlotCentered(ps, true);
  36.  
  37.  
  38.                     // We'll use the standard DWF PC3, as for today we're just plotting to file
  39.                     psv.SetPlotConfigurationName( ps, "DWG To PDF.pc3", "ARCH_E1_(30.00_x_42.00_Inches)");
  40.                     psv.SetPlotPaperUnits(ps, PlotPaperUnit.Inches);
  41.                     psv.SetPlotRotation(ps, PlotRotation.Degrees090);
  42.                     psv.RefreshLists(ps);
  43.                     psv.SetCurrentStyleSheet(ps, "Stellar FullSize Mono.ctb");
  44.  
  45.  
  46.                     // We need to link the PlotInfo to the PlotSettings and then validate it
  47.  
  48.                     pi.OverrideSettings = ps;
  49.                     PlotInfoValidator piv = new PlotInfoValidator();
  50.                     piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
  51.                     piv.Validate(pi);
  52.  
  53.  
  54.                     // A PlotEngine does the actual plotting (can also create one for Preview)
  55.  
  56.                     if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
  57.                     {
  58.                         PlotEngine pe = PlotFactory.CreatePublishEngine();
  59.                         using (pe)
  60.                         {
  61.  
  62.                             // Create a Progress Dialog to provide info and allow the user to cancel
  63.  
  64.                             PlotProgressDialog ppd = new PlotProgressDialog(false, 1, true);
  65.  
  66.                             using (ppd)
  67.                             {
  68.  
  69.                                 ppd.set_PlotMsgString(
  70.  
  71.                                   PlotMessageIndex.DialogTitle,
  72.  
  73.                                   "Custom Plot Progress"
  74.  
  75.                                 );
  76.  
  77.                                 ppd.set_PlotMsgString(
  78.  
  79.                                   PlotMessageIndex.CancelJobButtonMessage,
  80.  
  81.                                   "Cancel Job"
  82.  
  83.                                 );
  84.  
  85.                                 ppd.set_PlotMsgString(
  86.  
  87.                                   PlotMessageIndex.CancelSheetButtonMessage,
  88.  
  89.                                   "Cancel Sheet"
  90.  
  91.                                 );
  92.  
  93.                                 ppd.set_PlotMsgString(
  94.  
  95.                                   PlotMessageIndex.SheetSetProgressCaption,
  96.  
  97.                                   "Sheet Set Progress"
  98.  
  99.                                 );
  100.  
  101.                                 ppd.set_PlotMsgString(
  102.  
  103.                                   PlotMessageIndex.SheetProgressCaption,
  104.  
  105.                                   "Sheet Progress"
  106.  
  107.                                 );
  108.  
  109.                                 ppd.LowerPlotProgressRange = 0;
  110.  
  111.                                 ppd.UpperPlotProgressRange = 100;
  112.  
  113.                                 ppd.PlotProgressPos = 0;
  114.  
  115.  
  116.                                 // Let's start the plot, at last
  117.  
  118.  
  119.                                 ppd.OnBeginPlot();
  120.  
  121.                                 ppd.IsVisible = true;
  122.  
  123.                                 pe.BeginPlot(ppd, null);
  124.  
  125.  
  126.                                 // We'll be plotting a single document
  127.  
  128.  
  129.                                 pe.BeginDocument(
  130.  
  131.                                   pi,
  132.  
  133.                                   dwg,
  134.  
  135.                                   null,
  136.  
  137.                                   1,
  138.  
  139.                                   true, // Let's plot to file
  140.  
  141.                                   "c:\\test-output"
  142.  
  143.                                 );
  144.  
  145.  
  146.                                 // Which contains a single sheet
  147.  
  148.  
  149.                                 ppd.OnBeginSheet();
  150.  
  151.  
  152.                                 ppd.LowerSheetProgressRange = 0;
  153.  
  154.                                 ppd.UpperSheetProgressRange = 100;
  155.  
  156.                                 ppd.SheetProgressPos = 0;
  157.  
  158.  
  159.                                 PlotPageInfo ppi = new PlotPageInfo();
  160.  
  161.                                 pe.BeginPage(
  162.  
  163.                                   ppi,
  164.  
  165.                                   pi,
  166.  
  167.                                   true,
  168.  
  169.                                   null
  170.  
  171.                                 );
  172.  
  173.                                 pe.BeginGenerateGraphics(null);
  174.  
  175.                                 pe.EndGenerateGraphics(null);
  176.  
  177.  
  178.                                 // Finish the sheet
  179.  
  180.                                 pe.EndPage(null);
  181.  
  182.                                 ppd.SheetProgressPos = 100;
  183.  
  184.                                 ppd.OnEndSheet();
  185.  
  186.  
  187.                                 // Finish the document
  188.  
  189.  
  190.                                 pe.EndDocument(null);
  191.  
  192.  
  193.                                 // And finish the plot
  194.  
  195.  
  196.                                 ppd.PlotProgressPos = 100;
  197.  
  198.                                 ppd.OnEndPlot();
  199.  
  200.                                 pe.EndPlot(null);
  201.  
  202.                             }
  203.  
  204.                         }
  205.  
  206.                     }
  207.  
  208.                     else
  209.  
  210.                     {
  211.                         // Show this message
  212.                         MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
  213.                     }
  214.                 }
Advertisement
Add Comment
Please, Sign In to add comment