- 积分
- 154
- 明经币
- 个
- 注册时间
- 2010-6-23
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
请大家帮我看看,百思不得其解!
.net3.5+cad2010
用于打印的代码如下:-
-
- Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
- try
- {
- using (DocumentLock docLock = TlsETM.acDoc.LockDocument())
- {
- Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
- TlsETM tm = new TlsETM();
- PlotInfo pi = new PlotInfo();
- PlotInfoValidator piv = new PlotInfoValidator();
- piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
- ObjectIdCollection layoutsToPlot = new ObjectIdCollection();
- BlockTable bt = (BlockTable)tm.GetObject(TlsETM.CurrentDatabase.BlockTableId, OpenMode.ForRead);
- foreach (ObjectId btrId in bt)
- {
- BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead);
- if (btr.IsLayout && btr.Name.ToUpper() != BlockTableRecord.ModelSpace.ToUpper())
- {
- layoutsToPlot.Add(btrId);
- }
- }
- TlsETM.acDoc.LockDocument();
- foreach (ObjectId btrId in layoutsToPlot)
- {
- BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead);
- Layout lo = (Layout)tm.GetObject(btr.LayoutId, OpenMode.ForRead);
- PlotSettings ps = new PlotSettings(lo.ModelType);
- ps.CopyFrom(lo);
- PlotSettingsValidator psv = PlotSettingsValidator.Current;
- psv.SetPlotConfigurationName(ps, "Foxit Phantom Printer", "A3");
- psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout);
- psv.SetUseStandardScale(ps, true);
- psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
- //psv.SetPlotCentered(ps, true);
- psv.SetPlotRotation(ps, PlotRotation.Degrees090);
- psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);
- pi.Layout = btr.LayoutId;
- LayoutManager.Current.CurrentLayout = lo.LayoutName;
- pi.OverrideSettings = ps;
- piv.Validate(pi);
- while (PlotFactory.ProcessPlotState != ProcessPlotState.NotPlotting)
- Thread.Sleep(100);
- Thread.Sleep(2000);
- using (acPlEng = PlotFactory.CreatePublishEngine())
- {
- // Start to plot the layout
- acPlEng.BeginPlot(null, null);
- string PDFName = TlsETM.acDoc.Name.ToLower().Replace(".dwg", "-") + lo.LayoutName;
- acPlEng.BeginDocument(pi, TlsETM.acDoc.Name, null, 1, true, PDFName);
- TlsETM.Editor.WriteMessage("\r\n" + PDFName + "\r\n");
- // Plot the first sheet/layout
- PlotPageInfo acPlPageInfo = new PlotPageInfo();
- acPlEng.BeginPage(acPlPageInfo, pi, true, null);
- acPlEng.BeginGenerateGraphics(null);
- acPlEng.EndGenerateGraphics(null);
- // Finish plotting the sheet/layout
- acPlEng.EndPage(null);
- // Finish plotting the document
- acPlEng.EndDocument(null);
- // Finish the plot
- acPlEng.EndPlot(null);
- }
- }
- }
- }
- catch (System.Exception ex)
- {
- }
- finally
- {
- Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BACKGROUNDPLOT", 2);
- }
|
|