乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 134|回复: 9

Kean专题(12)—Plotting

[复制链接]

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-20 16:17:00 | 显示全部楼层 |阅读模式
一、使用Design Review 2008的批打印
May 10, 2007
Automating batch printing of DWF files using Design Review 2008
We sometimes receive questions on how best to automate the printing of DWF files. Autodesk Design Review 2008 now has a new Batch Print Plug-in enabling just this.
Once you've installed the plug-in, you'll be able to use the Batch Print Wizard in Design Review (on the file menu, once a DWF has been loaded). This Wizard allows you to configure a batch job for Design Review to process and save it to a BPJ (Batch Print Job) file. This BPJ (which is basically a very simple XML file) can then be used to drive the batch print process automatically.
The next logical step is clearly to create the BPJ programmatically, which can be done using a number of XML libraries (MS XML etc.) or simply by writing out a text file using your favourite string output routines.
So let's look at creating the BPJ file "manually" using the Batch Print Wizard.
Here's the second screen you'll see, once you've skipped the welcome:

rf0vwp3firu.png

rf0vwp3firu.png


When you've selected the files you wish to print and added them to the right-hand side using the ">" button, you can move on to the next page:

l4oi5lyxr1o.png

l4oi5lyxr1o.png


This is where you modify the print setup for each of your DWFs, by clicking on the item and hitting &quotrint Setup", or just double-clicking the item.

4ohs0a2yuzx.png

4ohs0a2yuzx.png


And then you're ready to save the BPJ file (or just &quotrint" directly).
I saved mine as "c:\My Documents\MyFiles.bpj", and here are its contents, with additional whitespace added for readability:复制代码This is clearly straightforward to create programmatically from your application. The next question is how best to automate the print process, now we have our BPJ.
The simplest way is to call the Design Review executable with the BPJ file as a command-line argument:

i0nyawrmnh0.png

i0nyawrmnh0.png


The executable returns straight away, and you'll see a log file created in the same location as the BPJ (in my case "c:\My Documents\MyFiles.log"), detailing the results of the print job:复制代码This log file can be parsed programmatically if it's important for your application to know whether any pages had difficulty printing.

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-21 11:34:00 | 显示全部楼层
二、使用NetApi实现简单的打印任务
September 25, 2007
Driving a basic AutoCAD plot using .NET
I just missed my connecting flight in Chicago, so have 3 hours to pass until the next, and decided to post some code I finally got around to writing on the plane from Zurich.
I've had a few requests for code showing how to plot using the .NET API in AutoCAD. There's an existing ObjectARX (C++) sample on the SDK, under samples/editor/AsdkPlotAPI, but there isn't a publicly posted .NET version right now.
Here's the C# code I put together. Please bear in mind that it was written during less than ideal coding conditions, and I haven't spent a substantial amount of time going through it... it seems to work fine for me, but do post a comment if you have trouble with it.
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.PlottingServices;
  7. namespace PlottingApplication
  8. {
  9.   public class PlottingCommands
  10.   {
  11.     [CommandMethod("simplot")]
  12.     static public void SimplePlot()
  13.     {
  14.       Document doc =
  15.         Application.DocumentManager.MdiActiveDocument;
  16.       Editor ed = doc.Editor;
  17.       Database db = doc.Database;
  18.       Transaction tr =
  19.         db.TransactionManager.StartTransaction();
  20.       using (tr)
  21.       {
  22.         // We'll be plotting the current layout
  23.         BlockTableRecord btr =
  24.           (BlockTableRecord)tr.GetObject(
  25.             db.CurrentSpaceId,
  26.             OpenMode.ForRead
  27.           );
  28.         Layout lo =
  29.           (Layout)tr.GetObject(
  30.             btr.LayoutId,
  31.             OpenMode.ForRead
  32.           );
  33.         // We need a PlotInfo object
  34.         // linked to the layout
  35.         PlotInfo pi = new PlotInfo();
  36.         pi.Layout = btr.LayoutId;
  37.         // We need a PlotSettings object
  38.         // based on the layout settings
  39.         // which we then customize
  40.         PlotSettings ps =
  41.           new PlotSettings(lo.ModelType);
  42.         ps.CopyFrom(lo);
  43.         // The PlotSettingsValidator helps
  44.         // create a valid PlotSettings object
  45.         PlotSettingsValidator psv =
  46.           PlotSettingsValidator.Current;
  47.         // We'll plot the extents, centered and
  48.         // scaled to fit
  49.         psv.SetPlotType(
  50.           ps,
  51.           Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
  52.         );
  53.         psv.SetUseStandardScale(ps, true);
  54.         psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  55.         psv.SetPlotCentered(ps, true);
  56.         // We'll use the standard DWF PC3, as
  57.         // for today we're just plotting to file
  58.         psv.SetPlotConfigurationName(
  59.           ps,
  60.           "DWF6 ePlot.pc3",
  61.           "ANSI_A_(8.50_x_11.00_Inches)"
  62.         );
  63.         // We need to link the PlotInfo to the
  64.         // PlotSettings and then validate it
  65.         pi.OverrideSettings = ps;
  66.         PlotInfoValidator piv =
  67.           new PlotInfoValidator();
  68.         piv.MediaMatchingPolicy =
  69.           MatchingPolicy.MatchEnabled;
  70.         piv.Validate(pi);
  71.         // A PlotEngine does the actual plotting
  72.         // (can also create one for Preview)
  73.         if (PlotFactory.ProcessPlotState ==
  74.             ProcessPlotState.NotPlotting)
  75.         {
  76.           PlotEngine pe =
  77.             PlotFactory.CreatePublishEngine();
  78.           using (pe)
  79.           {
  80.             // Create a Progress Dialog to provide info
  81.             // and allow thej user to cancel
  82.             PlotProgressDialog ppd =
  83.               new PlotProgressDialog(false, 1, true);
  84.             using (ppd)
  85.             {
  86.               ppd.set_PlotMsgString(
  87.                 PlotMessageIndex.DialogTitle,
  88.                 "Custom Plot Progress"
  89.               );
  90.               ppd.set_PlotMsgString(
  91.                 PlotMessageIndex.CancelJobButtonMessage,
  92.                 "Cancel Job"
  93.               );
  94.               ppd.set_PlotMsgString(
  95.                 PlotMessageIndex.CancelSheetButtonMessage,
  96.                 "Cancel Sheet"
  97.               );
  98.               ppd.set_PlotMsgString(
  99.                 PlotMessageIndex.SheetSetProgressCaption,
  100.                 "Sheet Set Progress"
  101.               );
  102.               ppd.set_PlotMsgString(
  103.                 PlotMessageIndex.SheetProgressCaption,
  104.                 "Sheet Progress"
  105.               );
  106.               ppd.LowerPlotProgressRange = 0;
  107.               ppd.UpperPlotProgressRange = 100;
  108.               ppd.PlotProgressPos = 0;
  109.               // Let's start the plot, at last
  110.               ppd.OnBeginPlot();
  111.               ppd.IsVisible = true;
  112.               pe.BeginPlot(ppd, null);
  113.               // We'll be plotting a single document
  114.               pe.BeginDocument(
  115.                 pi,
  116.                 doc.Name,
  117.                 null,
  118.                 1,
  119.                 true, // Let's plot to file
  120.                 "c:\\test-output"
  121.               );
  122.               // Which contains a single sheet
  123.               ppd.OnBeginSheet();
  124.               ppd.LowerSheetProgressRange = 0;
  125.               ppd.UpperSheetProgressRange = 100;
  126.               ppd.SheetProgressPos = 0;
  127.               PlotPageInfo ppi = new PlotPageInfo();
  128.               pe.BeginPage(
  129.                 ppi,
  130.                 pi,
  131.                 true,
  132.                 null
  133.               );
  134.               pe.BeginGenerateGraphics(null);
  135.               pe.EndGenerateGraphics(null);
  136.               // Finish the sheet
  137.               pe.EndPage(null);
  138.               ppd.SheetProgressPos = 100;
  139.               ppd.OnEndSheet();
  140.               // Finish the document
  141.               pe.EndDocument(null);
  142.               // And finish the plot
  143.               ppd.PlotProgressPos = 100;
  144.               ppd.OnEndPlot();
  145.               pe.EndPlot(null);
  146.             }
  147.           }
  148.         }
  149.         else
  150.         {
  151.           ed.WriteMessage(
  152.             "\nAnother plot is in progress."
  153.           );
  154.         }
  155.       }
  156.     }
  157.   }
  158. }
A few comments on the code: I chose to plot to a file using the standard DWF plot driver/PC3 file, mainly as it avoids having to second-guess what printers/plotters everyone uses. :-) The SDK sample populates comboboxes in a dialog to allow selection of the device and the media size, but I've just gone with a choice that should work on all systems.
Here's what you should see when you launch the SIMPLOT command:

sjktxmmbgym.png

sjktxmmbgym.png


The output file should be created in "c:\test-output.dwf".
I added a simple check to fail gracefully when another plot is in progress... as this code will drive either a foreground or a background plot (depending on the value of the BACKGROUNDPLOT system variable), there's clear scope for failure if the code doesn't check via PlotFactory.ProcessPlotState (or handle the exception if another plot is already happening when you call PlotFactory.CreatePublishEngine()).
Now that I'm online I've found there's quite a similar code sample to the ADN site (also converted from the original SDK sample, I suspect):
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-21 11:40:00 | 显示全部楼层
三、使用NetApi实现多表打印任务
September 29, 2007
Driving a multi-sheet AutoCAD plot using .NET
Somewhat symmetrically I’m posting this from Chicago airport, once again, but thankfully I’m now on my way home. It was a busy week of meetings, but I did get the chance to put together some code that extended the last post into the realm of multi-sheet plot jobs.
The following code took some work, but I finally managed to iron out the obvious wrinkles and put together an approach to plot multiple sheets into a single document. The standard DWF6 driver doesn’t appear to support multiple sheet jobs (directly, at least), so I chose to use the DWFx driver that I probably downloaded and installed from here.
I haven’t “diffed” and colour-coded the changed lines with the previous post, as there ended up being quite a lot of swapping around etc., but you should be able to perform that comparison yourself, if you so wish.
Here’s the C# code:
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.PlottingServices;
  7. namespace PlottingApplication
  8. {
  9.   public class PlottingCommands
  10.   {
  11.     [CommandMethod("mplot")]
  12.     static public void MultiSheetPlot()
  13.     {
  14.       Document doc =
  15.         Application.DocumentManager.MdiActiveDocument;
  16.       Editor ed = doc.Editor;
  17.       Database db = doc.Database;
  18.       Transaction tr =
  19.         db.TransactionManager.StartTransaction();
  20.       using (tr)
  21.       {
  22.         BlockTable bt =
  23.           (BlockTable)tr.GetObject(
  24.             db.BlockTableId,
  25.             OpenMode.ForRead
  26.           );
  27.         PlotInfo pi = new PlotInfo();
  28.         PlotInfoValidator piv =
  29.           new PlotInfoValidator();
  30.         piv.MediaMatchingPolicy =
  31.           MatchingPolicy.MatchEnabled;
  32.         // A PlotEngine does the actual plotting
  33.         // (can also create one for Preview)
  34.         if (PlotFactory.ProcessPlotState ==
  35.             ProcessPlotState.NotPlotting)
  36.         {
  37.           PlotEngine pe =
  38.             PlotFactory.CreatePublishEngine();
  39.           using (pe)
  40.           {
  41.             // Create a Progress Dialog to provide info
  42.             // and allow thej user to cancel
  43.             PlotProgressDialog ppd =
  44.               new PlotProgressDialog(false, 1, true);
  45.             using (ppd)
  46.             {
  47.               ObjectIdCollection layoutsToPlot =
  48.                 new ObjectIdCollection();
  49.               foreach (ObjectId btrId in bt)
  50.               {
  51.                 BlockTableRecord btr =
  52.                   (BlockTableRecord)tr.GetObject(
  53.                     btrId,
  54.                     OpenMode.ForRead
  55.                   );
  56.                 if (btr.IsLayout &&
  57.                     btr.Name.ToUpper() !=
  58.                       BlockTableRecord.ModelSpace.ToUpper())
  59.                 {
  60.                   layoutsToPlot.Add(btrId);
  61.                 }
  62.               }
  63.               int numSheet = 1;
  64.               foreach (ObjectId btrId in layoutsToPlot)
  65.               {
  66.                 BlockTableRecord btr =
  67.                   (BlockTableRecord)tr.GetObject(
  68.                     btrId,
  69.                     OpenMode.ForRead
  70.                   );
  71.                 Layout lo =
  72.                   (Layout)tr.GetObject(
  73.                     btr.LayoutId,
  74.                     OpenMode.ForRead
  75.                   );
  76.                 // We need a PlotSettings object
  77.                 // based on the layout settings
  78.                 // which we then customize
  79.                 PlotSettings ps =
  80.                   new PlotSettings(lo.ModelType);
  81.                 ps.CopyFrom(lo);
  82.                 // The PlotSettingsValidator helps
  83.                 // create a valid PlotSettings object
  84.                 PlotSettingsValidator psv =
  85.                   PlotSettingsValidator.Current;
  86.                 // We'll plot the extents, centered and
  87.                 // scaled to fit
  88.                 psv.SetPlotType(
  89.                   ps,
  90.                 Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
  91.                 );
  92.                 psv.SetUseStandardScale(ps, true);
  93.                 psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  94.                 psv.SetPlotCentered(ps, true);
  95.                 // We'll use the standard DWFx PC3, as
  96.                 // this supports multiple sheets
  97.                 psv.SetPlotConfigurationName(
  98.                   ps,
  99.                   "DWFx ePlot (XPS Compatible).pc3",
  100.                   "ANSI_A_(8.50_x_11.00_Inches)"
  101.                 );
  102.                 // We need a PlotInfo object
  103.                 // linked to the layout
  104.                 pi.Layout = btr.LayoutId;
  105.                 // Make the layout we're plotting current
  106.                 LayoutManager.Current.CurrentLayout =
  107.                   lo.LayoutName;
  108.                 // We need to link the PlotInfo to the
  109.                 // PlotSettings and then validate it
  110.                 pi.OverrideSettings = ps;
  111.                 piv.Validate(pi);
  112.                 if (numSheet == 1)
  113.                 {
  114.                   ppd.set_PlotMsgString(
  115.                     PlotMessageIndex.DialogTitle,
  116.                     "Custom Plot Progress"
  117.                   );
  118.                   ppd.set_PlotMsgString(
  119.                     PlotMessageIndex.CancelJobButtonMessage,
  120.                     "Cancel Job"
  121.                   );
  122.                   ppd.set_PlotMsgString(
  123.                     PlotMessageIndex.CancelSheetButtonMessage,
  124.                     "Cancel Sheet"
  125.                   );
  126.                   ppd.set_PlotMsgString(
  127.                     PlotMessageIndex.SheetSetProgressCaption,
  128.                     "Sheet Set Progress"
  129.                   );
  130.                   ppd.set_PlotMsgString(
  131.                     PlotMessageIndex.SheetProgressCaption,
  132.                     "Sheet Progress"
  133.                   );
  134.                   ppd.LowerPlotProgressRange = 0;
  135.                   ppd.UpperPlotProgressRange = 100;
  136.                   ppd.PlotProgressPos = 0;
  137.                   // Let's start the plot, at last
  138.                   ppd.OnBeginPlot();
  139.                   ppd.IsVisible = true;
  140.                   pe.BeginPlot(ppd, null);
  141.                   // We'll be plotting a single document
  142.                   pe.BeginDocument(
  143.                     pi,
  144.                     doc.Name,
  145.                     null,
  146.                     1,
  147.                     true, // Let's plot to file
  148.                     "c:\\test-multi-sheet"
  149.                   );
  150.                 }
  151.                 // Which may contain multiple sheets
  152.                 ppd.StatusMsgString =
  153.                   "Plotting " +
  154.                   doc.Name.Substring(
  155.                     doc.Name.LastIndexOf("") + 1
  156.                   ) +
  157.                   " - sheet " + numSheet.ToString() +
  158.                   " of " + layoutsToPlot.Count.ToString();
  159.                 ppd.OnBeginSheet();
  160.                 ppd.LowerSheetProgressRange = 0;
  161.                 ppd.UpperSheetProgressRange = 100;
  162.                 ppd.SheetProgressPos = 0;
  163.                 PlotPageInfo ppi = new PlotPageInfo();
  164.                 pe.BeginPage(
  165.                   ppi,
  166.                   pi,
  167.                   (numSheet == layoutsToPlot.Count),
  168.                   null
  169.                 );
  170.                 pe.BeginGenerateGraphics(null);
  171.                 ppd.SheetProgressPos = 50;
  172.                 pe.EndGenerateGraphics(null);
  173.                 // Finish the sheet
  174.                 pe.EndPage(null);
  175.                 ppd.SheetProgressPos = 100;
  176.                 ppd.OnEndSheet();
  177.                 numSheet++;
  178.               }
  179.               // Finish the document
  180.               pe.EndDocument(null);
  181.               // And finish the plot
  182.               ppd.PlotProgressPos = 100;
  183.               ppd.OnEndPlot();
  184.               pe.EndPlot(null);
  185.             }
  186.           }
  187.         }
  188.         else
  189.         {
  190.           ed.WriteMessage(
  191.             "\nAnother plot is in progress."
  192.           );
  193.         }
  194.       }
  195.     }
  196.   }
  197. }
The output of the MPLOT command will be created in “c:\test-multi-sheet.dwfx”, which can then be viewed using Autodesk Design Review 2008 or the XPS viewer that ships with Windows Vista or from here for Windows XP.
Update
I spent some more time looking at this code and noticed a minor issue... We need to tell the plot dialog that we're working with multiple sheets in its constructor. So we first need to count the sheets and then create the dialog. Here's the modified section of code:
  1.           PlotEngine pe =
  2.             PlotFactory.CreatePublishEngine();
  3.           using (pe)
  4.           {
  5.             // Collect all the paperspace layouts
  6.             // for plotting
  7.             ObjectIdCollection layoutsToPlot =
  8.               new ObjectIdCollection();
  9.             foreach (ObjectId btrId in bt)
  10.             {
  11.               BlockTableRecord btr =
  12.                 (BlockTableRecord)tr.GetObject(
  13.                   btrId,
  14.                   OpenMode.ForRead
  15.                 );
  16.               if (btr.IsLayout &&
  17.                   btr.Name.ToUpper() !=
  18.                     BlockTableRecord.ModelSpace.ToUpper())
  19.               {
  20.                 layoutsToPlot.Add(btrId);
  21.               }
  22.             }
  23.             // Create a Progress Dialog to provide info
  24.             // and allow thej user to cancel
  25.             PlotProgressDialog ppd =
  26.               new PlotProgressDialog(
  27.                 false,
  28.                 layoutsToPlot.Count,
  29.                 true
  30.               );
  31.             using (ppd)
  32.             {
This now leads to the plot progress dialog showing multiple progress bars:

axnuq535rkp.png

axnuq535rkp.png

回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-23 22:04:00 | 显示全部楼层
四、单表打印预览
October 01, 2007
Previewing and plotting a single sheet in AutoCAD using .NET
This week's posts take the code I threw together last week for single-sheet and multi-sheet plotting, and introduces the concept of "plot preview".
I'm learning as I go for much of this, so there are structural (although usually not functional) changes being made to the code as it develops. In this instance, for example, I've factored off common functionality needed by both previewing and plotting into a single helper function. This will no doubt evolve further (and change in structure) when I come to apply the principle to multi-sheet plotting later in the week.
Here's the C# code:
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.PlottingServices;
  6. namespace PlottingApplication
  7. {
  8.   public class PreviewCommands
  9.   {
  10.     [CommandMethod("simprev")]
  11.     static public void SimplePreview()
  12.     {
  13.       Document doc =
  14.         Application.DocumentManager.MdiActiveDocument;
  15.       Editor ed = doc.Editor;
  16.       Database db = doc.Database;
  17.       // PlotEngines do the previewing and plotting
  18.       if (PlotFactory.ProcessPlotState ==
  19.           ProcessPlotState.NotPlotting)
  20.       {
  21.         // First we preview...
  22.         PreviewEndPlotStatus stat;
  23.         PlotEngine pre =
  24.           PlotFactory.CreatePreviewEngine(
  25.             (int)PreviewEngineFlags.Plot
  26.           );
  27.         using (pre)
  28.         {
  29.           stat =
  30.             PlotOrPreview(
  31.               pre,
  32.               true,
  33.               db.CurrentSpaceId,
  34.               ""
  35.             );
  36.         }
  37.         if (stat == PreviewEndPlotStatus.Plot)
  38.         {
  39.           // And if the user asks, we plot...
  40.           PlotEngine ple =
  41.             PlotFactory.CreatePublishEngine();
  42.           stat =
  43.             PlotOrPreview(
  44.               ple,
  45.               false,
  46.               db.CurrentSpaceId,
  47.               "c:\\previewed-plot"
  48.             );
  49.         }
  50.       }
  51.       else
  52.       {
  53.         ed.WriteMessage(
  54.           "\nAnother plot is in progress."
  55.         );
  56.       }
  57.     }
  58.     static PreviewEndPlotStatus PlotOrPreview(
  59.       PlotEngine pe,
  60.       bool isPreview,
  61.       ObjectId spaceId,
  62.       string filename)
  63.     {
  64.       Document doc =
  65.         Application.DocumentManager.MdiActiveDocument;
  66.       Editor ed = doc.Editor;
  67.       Database db = doc.Database;
  68.       PreviewEndPlotStatus ret =
  69.         PreviewEndPlotStatus.Cancel;
  70.       Transaction tr =
  71.         db.TransactionManager.StartTransaction();
  72.       using (tr)
  73.       {
  74.         // We'll be plotting the current layout
  75.         BlockTableRecord btr =
  76.           (BlockTableRecord)tr.GetObject(
  77.             spaceId,
  78.             OpenMode.ForRead
  79.           );
  80.         Layout lo =
  81.           (Layout)tr.GetObject(
  82.             btr.LayoutId,
  83.             OpenMode.ForRead
  84.           );
  85.         // We need a PlotInfo object
  86.         // linked to the layout
  87.         PlotInfo pi = new PlotInfo();
  88.         pi.Layout = btr.LayoutId;
  89.         // We need a PlotSettings object
  90.         // based on the layout settings
  91.         // which we then customize
  92.         PlotSettings ps =
  93.           new PlotSettings(lo.ModelType);
  94.         ps.CopyFrom(lo);
  95.         // The PlotSettingsValidator helps
  96.         // create a valid PlotSettings object
  97.         PlotSettingsValidator psv =
  98.           PlotSettingsValidator.Current;
  99.         // We'll plot the extents, centered and
  100.         // scaled to fit
  101.         psv.SetPlotType(
  102.           ps,
  103.           Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
  104.         );
  105.         psv.SetUseStandardScale(ps, true);
  106.         psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  107.         psv.SetPlotCentered(ps, true);
  108.         // We'll use the standard DWF PC3, as
  109.         // for today we're just plotting to file
  110.         psv.SetPlotConfigurationName(
  111.           ps,
  112.           "DWF6 ePlot.pc3",
  113.           "ANSI_A_(8.50_x_11.00_Inches)"
  114.         );
  115.         // We need to link the PlotInfo to the
  116.         // PlotSettings and then validate it
  117.         pi.OverrideSettings = ps;
  118.         PlotInfoValidator piv =
  119.           new PlotInfoValidator();
  120.         piv.MediaMatchingPolicy =
  121.           MatchingPolicy.MatchEnabled;
  122.         piv.Validate(pi);
  123.         // Create a Progress Dialog to provide info
  124.         // and allow thej user to cancel
  125.         PlotProgressDialog ppd =
  126.           new PlotProgressDialog(isPreview, 1, true);
  127.         using (ppd)
  128.         {
  129.           ppd.set_PlotMsgString(
  130.             PlotMessageIndex.DialogTitle,
  131.             "Custom Preview Progress"
  132.           );
  133.           ppd.set_PlotMsgString(
  134.             PlotMessageIndex.SheetName,
  135.             doc.Name.Substring(
  136.               doc.Name.LastIndexOf("") + 1
  137.             )
  138.           );
  139.           ppd.set_PlotMsgString(
  140.             PlotMessageIndex.CancelJobButtonMessage,
  141.             "Cancel Job"
  142.           );
  143.           ppd.set_PlotMsgString(
  144.             PlotMessageIndex.CancelSheetButtonMessage,
  145.             "Cancel Sheet"
  146.           );
  147.           ppd.set_PlotMsgString(
  148.             PlotMessageIndex.SheetSetProgressCaption,
  149.             "Sheet Set Progress"
  150.           );
  151.           ppd.set_PlotMsgString(
  152.             PlotMessageIndex.SheetProgressCaption,
  153.             "Sheet Progress"
  154.           );
  155.           ppd.LowerPlotProgressRange = 0;
  156.           ppd.UpperPlotProgressRange = 100;
  157.           ppd.PlotProgressPos = 0;
  158.           // Let's start the plot/preview, at last
  159.           ppd.OnBeginPlot();
  160.           ppd.IsVisible = true;
  161.           pe.BeginPlot(ppd, null);
  162.           // We'll be plotting/previewing
  163.           // a single document
  164.           pe.BeginDocument(
  165.             pi,
  166.             doc.Name,
  167.             null,
  168.             1,
  169.             !isPreview,
  170.             filename
  171.           );
  172.           // Which contains a single sheet
  173.           ppd.OnBeginSheet();
  174.           ppd.LowerSheetProgressRange = 0;
  175.           ppd.UpperSheetProgressRange = 100;
  176.           ppd.SheetProgressPos = 0;
  177.           PlotPageInfo ppi = new PlotPageInfo();
  178.           pe.BeginPage(
  179.             ppi,
  180.             pi,
  181.             true,
  182.             null
  183.           );
  184.           pe.BeginGenerateGraphics(null);
  185.           ppd.SheetProgressPos = 50;
  186.           pe.EndGenerateGraphics(null);
  187.           // Finish the sheet
  188.           PreviewEndPlotInfo pepi =
  189.             new PreviewEndPlotInfo();
  190.           pe.EndPage(pepi);
  191.           ret = pepi.Status;
  192.           ppd.SheetProgressPos = 100;
  193.           ppd.OnEndSheet();
  194.           // Finish the document
  195.           pe.EndDocument(null);
  196.           // And finish the plot
  197.           ppd.PlotProgressPos = 100;
  198.           ppd.OnEndPlot();
  199.           pe.EndPlot(null);
  200.         }
  201.         // Committing is cheaper than aborting
  202.         tr.Commit();
  203.       }
  204.       return ret;
  205.     }
  206.   }
  207. }
When you execute the SIMPREV command, you receive enter a "preview" mode, from where you can either cancel or plot. The trick was really in determining the button selected by the user, which we do by passing an appropriate object (of class PreviewEndPlotInfo) into the EndPage() function, to collect information on what the users selects. The next post will take this further, allowing the user to cycle through multiple sheets using "next" and "previous" buttons.
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-23 22:07:00 | 显示全部楼层
五、多表打印预览
October 04, 2007
Previewing and plotting multiple sheets in AutoCAD using .NET
This was a fun one to work on. The code in this post combines and extends upon techniques shown in two earlier posts: one showing how to plot multiple sheets and the other showing how to preview a single-sheet plot.
One of the key differences when plotting or previewing is that while plotting can directly support multiple sheets (assuming the device does so), previewing does not. The good news is that AutoCAD provides you the user interface elements to allow cycling through plots: the user is provided with "Next" and &quotrevious" buttons - it's then up to you to implement the appropriate logic to preview different sheets when the buttons are used.
I chose to use the same helper function for both preview and plot, even though they are a little different in nature. The reason is obvious (to me, at least) - it reduces the amount of code to debug and maintain - but it might, for some, make the code a little less easy to read. Ultimately the trick I used was to reduce the set of sheets being handled at the beginning of the function to a single sheet in the case of a preview, which allowed me to combine both approaches in a single function.
Here's the C# code:
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.PlottingServices;
  6. using System.Collections.Generic;
  7. namespace PlottingApplication
  8. {
  9.   public class PreviewCommands
  10.   {
  11.     [CommandMethod("mprev")]
  12.     static public void MultiSheetPreview()
  13.     {
  14.       Document doc =
  15.         Application.DocumentManager.MdiActiveDocument;
  16.       Editor ed = doc.Editor;
  17.       Database db = doc.Database;
  18.       ObjectIdCollection layoutsToPlot =
  19.         new ObjectIdCollection();
  20.       Transaction tr =
  21.         db.TransactionManager.StartTransaction();
  22.       using (tr)
  23.       {
  24.         // First we need to collect the layouts to
  25.         // plot/preview in tab order
  26.         SortedDictionary[i] layoutDict =
  27.           new SortedDictionary[i]();
  28.         BlockTable bt =
  29.           (BlockTable)tr.GetObject(
  30.             db.BlockTableId,
  31.             OpenMode.ForRead
  32.           );
  33.         foreach (ObjectId btrId in bt)
  34.         {
  35.           BlockTableRecord btr =
  36.             (BlockTableRecord)tr.GetObject(
  37.               btrId,
  38.               OpenMode.ForRead
  39.             );
  40.           if (btr.IsLayout &&
  41.               btr.Name.ToUpper() !=
  42.                 BlockTableRecord.ModelSpace.ToUpper())
  43.           {
  44.             // The dictionary we're using will
  45.             // sort on the tab order of the layout
  46.             Layout lo =
  47.               (Layout)tr.GetObject(
  48.                 btr.LayoutId,
  49.                 OpenMode.ForRead
  50.               );
  51.             layoutDict.Add(lo.TabOrder,btrId);
  52.           }
  53.         }
  54.         // Let's now get the layout IDs and add them to a
  55.         // standard ObjectIdCollection
  56.         SortedDictionary[i].ValueCollection vc =
  57.           layoutDict.Values;
  58.         foreach (ObjectId id in vc)
  59.         {
  60.           layoutsToPlot.Add(id);
  61.         }
  62.         // Committing is cheaper than aborting
  63.         tr.Commit();
  64.       }
  65.       // PlotEngines do the previewing and plotting
  66.       if (PlotFactory.ProcessPlotState ==
  67.           ProcessPlotState.NotPlotting)
  68.       {
  69.         int layoutNum = 0;
  70.         bool isFinished = false;
  71.         bool isReadyForPlot = false;
  72.         while (!isFinished)
  73.         {
  74.           // Create the preview engine with the appropriate
  75.           // buttons enabled - this depends on which
  76.           // layout in the list is being previewed
  77.           PreviewEngineFlags flags =
  78.             PreviewEngineFlags.Plot;
  79.           if (layoutNum > 0)
  80.             flags |= PreviewEngineFlags.PreviousSheet;
  81.           if (layoutNum = 0)
  82.       {
  83.         // Preview is really pre-sheet, so we reduce the
  84.         // sheet collection to contain the one we want
  85.         layoutsToPlot = new ObjectIdCollection();
  86.         layoutsToPlot.Add(
  87.           layoutSet[layoutNumIfPreview]
  88.         );
  89.       }
  90.       else
  91.       {
  92.         // If we're plotting we need all the sheets,
  93.         // so copy the ObjectIds across
  94.         ObjectId[] ids = new ObjectId[layoutSet.Count];
  95.         layoutSet.CopyTo(ids,0);
  96.         layoutsToPlot = new ObjectIdCollection(ids);
  97.       }
  98.       Transaction tr =
  99.         db.TransactionManager.StartTransaction();
  100.       using (tr)
  101.       {
  102.         // Create a Progress Dialog to provide info
  103.         // and allow thej user to cancel
  104.         PlotProgressDialog ppd =
  105.           new PlotProgressDialog(
  106.             isPreview,
  107.             layoutsToPlot.Count,
  108.             true
  109.           );
  110.         using (ppd)
  111.         {
  112.           int numSheet = 1;
  113.           foreach (ObjectId btrId in layoutsToPlot)
  114.           {
  115.             BlockTableRecord btr =
  116.               (BlockTableRecord)tr.GetObject(
  117.                 btrId,
  118.                 OpenMode.ForRead
  119.               );
  120.             Layout lo =
  121.               (Layout)tr.GetObject(
  122.                 btr.LayoutId,
  123.                 OpenMode.ForRead
  124.               );
  125.             // We need a PlotSettings object
  126.             // based on the layout settings
  127.             // which we then customize
  128.             PlotSettings ps =
  129.               new PlotSettings(lo.ModelType);
  130.             ps.CopyFrom(lo);
  131.             // The PlotSettingsValidator helps
  132.             // create a valid PlotSettings object
  133.             PlotSettingsValidator psv =
  134.               PlotSettingsValidator.Current;
  135.             // We'll plot the extents, centered and
  136.             // scaled to fit
  137.             psv.SetPlotType(
  138.               ps,
  139.               Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
  140.             );
  141.             psv.SetUseStandardScale(ps, true);
  142.             psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  143.             psv.SetPlotCentered(ps, true);
  144.             // We'll use the standard DWFx PC3, as
  145.             // this supports multiple sheets
  146.             psv.SetPlotConfigurationName(
  147.               ps,
  148.               "DWFx ePlot (XPS Compatible).pc3",
  149.               "ANSI_A_(8.50_x_11.00_Inches)"
  150.             );
  151.             // We need a PlotInfo object
  152.             // linked to the layout
  153.             PlotInfo pi = new PlotInfo();
  154.             pi.Layout = btr.LayoutId;
  155.             // Make the layout we're plotting current
  156.             LayoutManager.Current.CurrentLayout =
  157.               lo.LayoutName;
  158.             // We need to link the PlotInfo to the
  159.             // PlotSettings and then validate it
  160.             pi.OverrideSettings = ps;
  161.             PlotInfoValidator piv =
  162.               new PlotInfoValidator();
  163.             piv.MediaMatchingPolicy =
  164.               MatchingPolicy.MatchEnabled;
  165.             piv.Validate(pi);
  166.             // We set the sheet name per sheet
  167.             ppd.set_PlotMsgString(
  168.               PlotMessageIndex.SheetName,
  169.               doc.Name.Substring(
  170.                 doc.Name.LastIndexOf("") + 1
  171.               ) +
  172.               " - " +
  173.               lo.LayoutName
  174.             );
  175.             if (numSheet == 1)
  176.             {
  177.               // All other messages get set once
  178.               ppd.set_PlotMsgString(
  179.                 PlotMessageIndex.DialogTitle,
  180.                 "Custom Preview Progress"
  181.               );
  182.               ppd.set_PlotMsgString(
  183.                 PlotMessageIndex.CancelJobButtonMessage,
  184.                 "Cancel Job"
  185.               );
  186.               ppd.set_PlotMsgString(
  187.                 PlotMessageIndex.CancelSheetButtonMessage,
  188.                 "Cancel Sheet"
  189.               );
  190.               ppd.set_PlotMsgString(
  191.                 PlotMessageIndex.SheetSetProgressCaption,
  192.                 "Sheet Set Progress"
  193.               );
  194.               ppd.set_PlotMsgString(
  195.                 PlotMessageIndex.SheetProgressCaption,
  196.                 "Sheet Progress"
  197.               );
  198.               ppd.LowerPlotProgressRange = 0;
  199.               ppd.UpperPlotProgressRange = 100;
  200.               ppd.PlotProgressPos = 0;
  201.               // Let's start the plot/preview, at last
  202.               ppd.OnBeginPlot();
  203.               ppd.IsVisible = true;
  204.               pe.BeginPlot(ppd, null);
  205.               // We'll be plotting a single document
  206.               pe.BeginDocument(
  207.                 pi,
  208.                 doc.Name,
  209.                 null,
  210.                 1,
  211.                 !isPreview,
  212.                 filename
  213.               );
  214.             }
  215.             // Which may contains multiple sheets
  216.             ppd.LowerSheetProgressRange = 0;
  217.             ppd.UpperSheetProgressRange = 100;
  218.             ppd.SheetProgressPos = 0;
  219.             PlotPageInfo ppi = new PlotPageInfo();
  220.             pe.BeginPage(
  221.               ppi,
  222.               pi,
  223.               (numSheet == layoutsToPlot.Count),
  224.               null
  225.             );
  226.             ppd.OnBeginSheet();
  227.             pe.BeginGenerateGraphics(null);
  228.             ppd.SheetProgressPos = 50;
  229.             pe.EndGenerateGraphics(null);
  230.             // Finish the sheet
  231.             PreviewEndPlotInfo pepi =
  232.               new PreviewEndPlotInfo();
  233.             pe.EndPage(pepi);
  234.             ret = pepi.Status;
  235.             ppd.SheetProgressPos = 100;
  236.             ppd.OnEndSheet();
  237.             numSheet++;
  238.             // Update the overall progress
  239.             ppd.PlotProgressPos +=
  240.               (100 / layoutsToPlot.Count);
  241.           }
  242.           // Finish the document
  243.           pe.EndDocument(null);
  244.           // And finish the plot
  245.           ppd.PlotProgressPos = 100;
  246.           ppd.OnEndPlot();
  247.           pe.EndPlot(null);
  248.         }
  249.       }
  250.       return ret;
  251.     }
  252.   }
  253. }
Here's what you see when you run the MPREV command:

mwcypdlx4pm.png

mwcypdlx4pm.png


Once you select the plot button, the plot gets driven as before:

v0ilkgj2j3h.png

v0ilkgj2j3h.png


回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-7-1 17:24:00 | 显示全部楼层
六、选择打印设备和打印介质
October 09, 2007
Allowing selection of an AutoCAD plot device and media name using .NET
A comment came in on this previous post regarding how best to know whether a media name is valid during your plot configuration.
There are a few approaches, other than the one I chose of hardcoding the device and media names. The first is to implement a user interface of some kind which allows the user to select the device and media names. Another approach for setting the media name is to use PlotSettingsValidator.SetClosestMediaName() to choose the media name that most closely matches the paper size you desire.
Today I'll focus on the first option, although I'm only going to implement a basic, command-line user interface. It should be straightforward to extend this to implement a WinForm with comboboxes for the device and media names.
I implemented a simple function called ChooseDeviceAndMedia() which queries the current device list, allows selection from it, and then gets the media name list and allows selection from that. I chose not to worry about displaying locale-specific names, for now - I'll leave that for a future post (let me know if you're interested :-).
Here's the function integrated into the C# code from this previous post, which defines a command called MPLOT:[code]
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.PlottingServices;
using System.Collections.Specialized;
namespace PlottingApplication
{
  public class PlottingCommands
  {
    static public string[] ChooseDeviceAndMedia()
    {
      Document doc =
        Application.DocumentManager.MdiActiveDocument;
      Editor ed = doc.Editor;
      // Assign default return values
      string devname = "", medname = "";
      PlotSettingsValidator psv =
        PlotSettingsValidator.Current;
      // Let's first select the device
      StringCollection devlist =
        psv.GetPlotDeviceList();
      for (int i = 0; i 复制代码
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-7-1 17:29:00 | 显示全部楼层
七、窗选打印
October 11, 2007
Plotting a window from AutoCAD using .NET
This post extends this previous post that dealt with driving a single-sheet AutoCAD plot by adding some code to handle selection and transformation of a window to plot.
First order of business was to allow the user to select the window to plot. For this I used the classic combination of Editor.GetPoint() for the first corner) and Editor.GetCorner() for the second. All well and good, but the points returned by these functions are in UCS (User Coordinate System) coordinates. Which meant that as it stood, the code would work just fine if (and only if) the view we were using to select the window was parallell with the World Coordinate System (and no additional UCS was in place). In order to deal with the very common scenario of either a UCS being used or the current modelspace view being orbited (etc.), we need to transform the current UCS coordinates into DCS, the Display Coordinate System.
Thankfully that's pretty easy: no need for matrices or anything, we simply use another old friend, acedTrans() (the ObjectARX equivalent of the (trans) function, for you LISPers out there). There isn't a direct equivalent for this function in the managed API (that I'm aware of), so we have to use P/Invoke to call the ObjectARX function. The technique is shown in this DevNote, for those of you that have access to the ADN website:
How to call acedTrans from .NET application?
Otherwise the changes to the original code are very minor: we need to set the extents of the window to plot and then set the plot type to "window", apparently in that order. AutoCAD complained when I initially made the calls in the opposite sequence.
Here's the C# code:
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.PlottingServices;
  6. using Autodesk.AutoCAD.Geometry;
  7. using System.Runtime.InteropServices;
  8. using System;
  9. namespace PlottingApplication
  10. {
  11.   public class SimplePlottingCommands
  12.   {
  13.     [DllImport("acad.exe",
  14.               CallingConvention = CallingConvention.Cdecl,
  15.               EntryPoint="acedTrans")
  16.     ]
  17.     static extern int acedTrans(
  18.       double[] point,
  19.       IntPtr fromRb,
  20.       IntPtr toRb,
  21.       int disp,
  22.       double[] result
  23.     );
  24.     [CommandMethod("winplot")]
  25.     static public void WindowPlot()
  26.     {
  27.       Document doc =
  28.         Application.DocumentManager.MdiActiveDocument;
  29.       Editor ed = doc.Editor;
  30.       Database db = doc.Database;
  31.       PromptPointOptions ppo =
  32.         new PromptPointOptions(
  33.           "\nSelect first corner of plot area: "
  34.         );
  35.       ppo.AllowNone = false;
  36.       PromptPointResult ppr =
  37.         ed.GetPoint(ppo);
  38.       if (ppr.Status != PromptStatus.OK)
  39.         return;
  40.       Point3d first = ppr.Value;
  41.       PromptCornerOptions pco =
  42.         new PromptCornerOptions(
  43.           "\nSelect second corner of plot area: ",
  44.           first
  45.         );
  46.       ppr = ed.GetCorner(pco);
  47.       if (ppr.Status != PromptStatus.OK)
  48.         return;
  49.       Point3d second = ppr.Value;
  50.       // Transform from UCS to DCS
  51.       ResultBuffer rbFrom =
  52.         new ResultBuffer(new TypedValue(5003, 1)),
  53.                   rbTo =
  54.         new ResultBuffer(new TypedValue(5003, 2));
  55.       double[] firres = new double[] { 0, 0, 0 };
  56.       double[] secres = new double[] { 0, 0, 0 };
  57.       // Transform the first point...
  58.       acedTrans(
  59.         first.ToArray(),
  60.         rbFrom.UnmanagedObject,
  61.         rbTo.UnmanagedObject,
  62.         0,
  63.         firres
  64.       );
  65.       // ... and the second
  66.       acedTrans(
  67.         second.ToArray(),
  68.         rbFrom.UnmanagedObject,
  69.         rbTo.UnmanagedObject,
  70.         0,
  71.         secres
  72.       );
  73.       // We can safely drop the Z-coord at this stage
  74.       Extents2d window =
  75.         new Extents2d(
  76.           firres[0],
  77.           firres[1],
  78.           secres[0],
  79.           secres[1]
  80.         );
  81.       Transaction tr =
  82.         db.TransactionManager.StartTransaction();
  83.       using (tr)
  84.       {
  85.         // We'll be plotting the current layout
  86.         BlockTableRecord btr =
  87.           (BlockTableRecord)tr.GetObject(
  88.             db.CurrentSpaceId,
  89.             OpenMode.ForRead
  90.           );
  91.         Layout lo =
  92.           (Layout)tr.GetObject(
  93.             btr.LayoutId,
  94.             OpenMode.ForRead
  95.           );
  96.         // We need a PlotInfo object
  97.         // linked to the layout
  98.         PlotInfo pi = new PlotInfo();
  99.         pi.Layout = btr.LayoutId;
  100.         // We need a PlotSettings object
  101.         // based on the layout settings
  102.         // which we then customize
  103.         PlotSettings ps =
  104.           new PlotSettings(lo.ModelType);
  105.         ps.CopyFrom(lo);
  106.         // The PlotSettingsValidator helps
  107.         // create a valid PlotSettings object
  108.         PlotSettingsValidator psv =
  109.           PlotSettingsValidator.Current;
  110.         // We'll plot the extents, centered and
  111.         // scaled to fit
  112.         psv.SetPlotWindowArea(ps, window);
  113.         psv.SetPlotType(
  114.           ps,
  115.         Autodesk.AutoCAD.DatabaseServices.PlotType.Window
  116.         );
  117.         psv.SetUseStandardScale(ps, true);
  118.         psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  119.         psv.SetPlotCentered(ps, true);
  120.         // We'll use the standard DWF PC3, as
  121.         // for today we're just plotting to file
  122.         psv.SetPlotConfigurationName(
  123.           ps,
  124.           "DWF6 ePlot.pc3",
  125.           "ANSI_A_(8.50_x_11.00_Inches)"
  126.         );
  127.         // We need to link the PlotInfo to the
  128.         // PlotSettings and then validate it
  129.         pi.OverrideSettings = ps;
  130.         PlotInfoValidator piv =
  131.           new PlotInfoValidator();
  132.         piv.MediaMatchingPolicy =
  133.           MatchingPolicy.MatchEnabled;
  134.         piv.Validate(pi);
  135.         // A PlotEngine does the actual plotting
  136.         // (can also create one for Preview)
  137.         if (PlotFactory.ProcessPlotState ==
  138.             ProcessPlotState.NotPlotting)
  139.         {
  140.           PlotEngine pe =
  141.             PlotFactory.CreatePublishEngine();
  142.           using (pe)
  143.           {
  144.             // Create a Progress Dialog to provide info
  145.             // and allow thej user to cancel
  146.             PlotProgressDialog ppd =
  147.               new PlotProgressDialog(false, 1, true);
  148.             using (ppd)
  149.             {
  150.               ppd.set_PlotMsgString(
  151.                 PlotMessageIndex.DialogTitle,
  152.                 "Custom Plot Progress"
  153.               );
  154.               ppd.set_PlotMsgString(
  155.                 PlotMessageIndex.CancelJobButtonMessage,
  156.                 "Cancel Job"
  157.               );
  158.               ppd.set_PlotMsgString(
  159.                 PlotMessageIndex.CancelSheetButtonMessage,
  160.                 "Cancel Sheet"
  161.               );
  162.               ppd.set_PlotMsgString(
  163.                 PlotMessageIndex.SheetSetProgressCaption,
  164.                 "Sheet Set Progress"
  165.               );
  166.               ppd.set_PlotMsgString(
  167.                 PlotMessageIndex.SheetProgressCaption,
  168.                 "Sheet Progress"
  169.               );
  170.               ppd.LowerPlotProgressRange = 0;
  171.               ppd.UpperPlotProgressRange = 100;
  172.               ppd.PlotProgressPos = 0;
  173.               // Let's start the plot, at last
  174.               ppd.OnBeginPlot();
  175.               ppd.IsVisible = true;
  176.               pe.BeginPlot(ppd, null);
  177.               // We'll be plotting a single document
  178.               pe.BeginDocument(
  179.                 pi,
  180.                 doc.Name,
  181.                 null,
  182.                 1,
  183.                 true, // Let's plot to file
  184.                 "c:\\test-output"
  185.               );
  186.               // Which contains a single sheet
  187.               ppd.OnBeginSheet();
  188.               ppd.LowerSheetProgressRange = 0;
  189.               ppd.UpperSheetProgressRange = 100;
  190.               ppd.SheetProgressPos = 0;
  191.               PlotPageInfo ppi = new PlotPageInfo();
  192.               pe.BeginPage(
  193.                 ppi,
  194.                 pi,
  195.                 true,
  196.                 null
  197.               );
  198.               pe.BeginGenerateGraphics(null);
  199.               pe.EndGenerateGraphics(null);
  200.               // Finish the sheet
  201.               pe.EndPage(null);
  202.               ppd.SheetProgressPos = 100;
  203.               ppd.OnEndSheet();
  204.               // Finish the document
  205.               pe.EndDocument(null);
  206.               // And finish the plot
  207.               ppd.PlotProgressPos = 100;
  208.               ppd.OnEndPlot();
  209.               pe.EndPlot(null);
  210.             }
  211.           }
  212.         }
  213.         else
  214.         {
  215.           ed.WriteMessage(
  216.             "\nAnother plot is in progress."
  217.           );
  218.         }
  219.       }
  220.     }
  221.   }
  222. }
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2015-12-9 23:41:00 | 显示全部楼层
有翻译过来的么,看着眼晕
回复

使用道具 举报

0

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
3
发表于 2017-12-2 14:20:00 | 显示全部楼层
有自定义图幅的方法吗?
回复

使用道具 举报

10

主题

31

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
71
发表于 2019-1-23 09:24:00 | 显示全部楼层
打印预览有没有调过了的?为啥一直卡在预览界面?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 02:49 , Processed in 1.274823 second(s), 75 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表