csharpnice 发表于 2010-9-4 12:23:00

.NET 打印出了问题 导致CAD奔溃

请大家帮我看看,百思不得其解!
.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);
            }


csharpnice 发表于 2010-9-4 12:25:00

<p>打印完了之后,CAD就死机了!</p>
<p>&nbsp;</p>
<p>实在找不出在什么地方会有问题</p>

csharpnice 发表于 2010-9-4 12:28:00

Unhandled e4034f4dh exception at fd3baa7dh

雪山飞狐_lzh 发表于 2010-9-4 12:45:00

<p>TlsETM tm = new TlsETM();</p>
<p>...</p>
<p>&nbsp;</p>
<p>=&gt;</p>
<p>using(TlsETM tm = new TlsETM())</p>
<p>{</p>
<p>...</p>
<p>}</p>
<p>&nbsp;</p>
<p>TlsETM.acDoc.LockDocument();</p>
<p>...</p>
<p>=&gt;</p>
<p>using(TlsETM.acDoc.LockDocument())</p>
<p>{</p>
<p>...</p>
<p>}</p>

onliboy 发表于 2010-9-4 23:21:00

我试试咯
页: [1]
查看完整版本: .NET 打印出了问题 导致CAD奔溃