明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1488|回复: 1

[基础] [求助]输出打印plt,无法指定打印样式

[复制链接]
发表于 2013-11-7 09:03 | 显示全部楼层 |阅读模式
开发环境 .Net 3.5+AutoCAD2010
下面的代码实现了打印输出plt,打印机是plt虚拟打印机,设置了打印样式,输出总是一个样子!

SetCurrentStyleSheet 这个是设置打印样式的方法吗?


  1. Document doc = Application.DocumentManager.MdiActiveDocument;
  2.             Editor ed = doc.Editor;
  3.             Database db = doc.Database;
  4.             Transaction tr = db.TransactionManager.StartTransaction();
  5.             using (tr)
  6.             {
  7.                 // We'll be plotting the current layout 绘制当前布局
  8.                 BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
  9.                 Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
  10.                 Extents2d PlotExtent=new Extents2d(minPnt,maxPnt);

  11.                 // We need a PlotInfo object linked to the layout 初始化PlotInfo的对象并与布局关联
  12.                 PlotInfo pi = new PlotInfo();
  13.                 pi.Layout = btr.LayoutId;
  14.                 // We need a PlotSettings object based on the layout settings  将PlotSettings对象初始化为基于布局设置
  15.                 // which we then customize  然后定制打印设置
  16.                 PlotSettings ps = new PlotSettings(lo.ModelType); //modeltype 区分布局空间,模型空间
  17.                 ps.CopyFrom(lo);
  18.                 // The PlotSettingsValidator helps create a valid PlotSettings object
  19.                 PlotSettingsValidator psv = PlotSettingsValidator.Current;

  20.                 //打印时在对象中使用打印样式
  21.                 ps.PlotPlotStyles = true;
  22.                 ps.PrintLineweights = true;

  23.                 //刷新打印设备,设置打印设备
  24.                 psv.SetPlotConfigurationName(ps, "PLT.pc3", "UserDefinedMetric (900.00 x 6000.00毫米)");
  25.                 //设置打印样式
  26.                 psv.SetCurrentStyleSheet(ps, sSheetStyleName);
  27.                 //设置打印尺寸
  28.                 //设置图纸单位
  29.                 psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);
  30.                 //设置打印方向
  31.                 //psv.SetPlotRotation(ps, PlotRotation.Degrees090);
  32.                 //设置打印比例
  33.                 //psv.SetUseStandardScale(ps, false);
  34.                 //CustomScale plotScale = new CustomScale(100, 1);
  35.                 //psv.SetCustomPrintScale(ps, plotScale);
  36.                 // 设置自定义打印偏移
  37.                 //psv.SetPlotOrigin(ps, new Point2d(0, 0));
  38.                 psv.SetUseStandardScale(ps, true);
  39.                 psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  40.                 psv.SetPlotCentered(ps, true);
  41.                 //设置打印的范围,中心和比例
  42.                 psv.SetPlotWindowArea(ps, PlotExtent);
  43.                 psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);

  44.                 //// We'll plot the extents, centered and scaled to fit
  45.                 ////设置打印的范围,中心和比例
  46.                 //psv.SetPlotWindowArea(ps, PlotExtent);
  47.                 //psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
  48.                 //psv.SetUseStandardScale(ps, true);
  49.                 //psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
  50.                 //psv.SetPlotCentered(ps, true);
  51.                 //// We'll use the standard DWF PC3, as for today we're just plotting to file
  52.                 ////使用标准的DWF PC3
  53.                 //psv.SetCurrentStyleSheet(ps, sSheetStyleName);
  54.                 //psv.SetPlotConfigurationName(ps, "CinqDIPLT.pc3", "UserDefinedMetric (900.00 x 6000.00毫米)");
  55.                 ////psv.SetPlotConfigurationName(ps, "CinqDWF.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
  56.                 //// We need to link the PlotInfo to the PlotSettings and then validate it
  57.                 pi.OverrideSettings = ps;
  58.                 PlotInfoValidator piv = new PlotInfoValidator();
  59.                 piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
  60.                 piv.Validate(pi);
  61.                 // A PlotEngine does the actual plotting (can also create one for Preview)
  62.                 if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
  63.                 {
  64.                     PlotEngine pe = PlotFactory.CreatePublishEngine();
  65.                     using (pe)
  66.                     {
  67.                         // Create a Progress Dialog to provide info and allow thej user to cancel
  68.                         PlotProgressDialog ppd =new PlotProgressDialog(false, 1, true);
  69.                         using (ppd)
  70.                         {
  71.                             ppd.set_PlotMsgString( PlotMessageIndex.DialogTitle, "Custom Plot Progress");
  72.                             ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
  73.                             ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage,"Cancel Sheet");
  74.                             ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption,"Sheet Set Progress");
  75.                             ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption,"Sheet Progress");
  76.                             ppd.LowerPlotProgressRange = 0;
  77.                             ppd.UpperPlotProgressRange = 100;
  78.                             ppd.PlotProgressPos = 0;
  79.                             // Let's start the plot, at last
  80.                             ppd.OnBeginPlot();
  81.                             ppd.IsVisible = true;
  82.                             pe.BeginPlot(ppd, null);
  83.                             // We'll be plotting a single document
  84.                             pe.BeginDocument( pi,doc.Name,null,1,true,"c:\\test-output"); // Let's plot to file
  85.                             // Which contains a single sheet
  86.                             ppd.OnBeginSheet();
  87.                             ppd.LowerSheetProgressRange = 0;
  88.                             ppd.UpperSheetProgressRange = 100;
  89.                             ppd.SheetProgressPos = 0;
  90.                             PlotPageInfo ppi = new PlotPageInfo();
  91.                             pe.BeginPage(ppi,pi,true,null);
  92.                             pe.BeginGenerateGraphics(null);
  93.                             pe.EndGenerateGraphics(null);
  94.                             // Finish the sheet
  95.                             pe.EndPage(null);
  96.                             ppd.SheetProgressPos = 100;
  97.                             ppd.OnEndSheet();
  98.                             // Finish the document
  99.                             pe.EndDocument(null);
  100.                             // And finish the plot
  101.                             ppd.PlotProgressPos = 100;
  102.                             ppd.OnEndPlot();
  103.                             pe.EndPlot(null);
  104.                         }
  105.                     }
  106.                 }
  107.                 else
  108.                 {
  109.                     ed.WriteMessage("\nAnother plot is in progress.");
  110.                 }
  111.             }

发表于 2014-5-6 23:09 | 显示全部楼层
学习一下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-2 13:06 , Processed in 0.268955 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表