- 积分
- 1299
- 明经币
- 个
- 注册时间
- 2012-8-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
开发环境 .Net 3.5+AutoCAD2010
下面的代码实现了打印输出plt,打印机是plt虚拟打印机,设置了打印样式,输出总是一个样子!
SetCurrentStyleSheet 这个是设置打印样式的方法吗?
- 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);
- Extents2d PlotExtent=new Extents2d(minPnt,maxPnt);
- // We need a PlotInfo object linked to the layout 初始化PlotInfo的对象并与布局关联
- PlotInfo pi = new PlotInfo();
- pi.Layout = btr.LayoutId;
- // We need a PlotSettings object based on the layout settings 将PlotSettings对象初始化为基于布局设置
- // which we then customize 然后定制打印设置
- PlotSettings ps = new PlotSettings(lo.ModelType); //modeltype 区分布局空间,模型空间
- ps.CopyFrom(lo);
- // The PlotSettingsValidator helps create a valid PlotSettings object
- PlotSettingsValidator psv = PlotSettingsValidator.Current;
- //打印时在对象中使用打印样式
- ps.PlotPlotStyles = true;
- ps.PrintLineweights = true;
- //刷新打印设备,设置打印设备
- psv.SetPlotConfigurationName(ps, "PLT.pc3", "UserDefinedMetric (900.00 x 6000.00毫米)");
- //设置打印样式
- psv.SetCurrentStyleSheet(ps, sSheetStyleName);
- //设置打印尺寸
- //设置图纸单位
- psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);
- //设置打印方向
- //psv.SetPlotRotation(ps, PlotRotation.Degrees090);
- //设置打印比例
- //psv.SetUseStandardScale(ps, false);
- //CustomScale plotScale = new CustomScale(100, 1);
- //psv.SetCustomPrintScale(ps, plotScale);
- // 设置自定义打印偏移
- //psv.SetPlotOrigin(ps, new Point2d(0, 0));
- psv.SetUseStandardScale(ps, true);
- psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
- psv.SetPlotCentered(ps, true);
- //设置打印的范围,中心和比例
- psv.SetPlotWindowArea(ps, PlotExtent);
- psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
- //// We'll plot the extents, centered and scaled to fit
- ////设置打印的范围,中心和比例
- //psv.SetPlotWindowArea(ps, PlotExtent);
- //psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
- //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
- ////使用标准的DWF PC3
- //psv.SetCurrentStyleSheet(ps, sSheetStyleName);
- //psv.SetPlotConfigurationName(ps, "CinqDIPLT.pc3", "UserDefinedMetric (900.00 x 6000.00毫米)");
- ////psv.SetPlotConfigurationName(ps, "CinqDWF.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
- //// 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,"c:\\test-output"); // Let's plot to file
- // 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.");
- }
- }
|
|