.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);
}
<p>打印完了之后,CAD就死机了!</p>
<p> </p>
<p>实在找不出在什么地方会有问题</p> Unhandled e4034f4dh exception at fd3baa7dh <p>TlsETM tm = new TlsETM();</p>
<p>...</p>
<p> </p>
<p>=></p>
<p>using(TlsETM tm = new TlsETM())</p>
<p>{</p>
<p>...</p>
<p>}</p>
<p> </p>
<p>TlsETM.acDoc.LockDocument();</p>
<p>...</p>
<p>=></p>
<p>using(TlsETM.acDoc.LockDocument())</p>
<p>{</p>
<p>...</p>
<p>}</p> 我试试咯
页:
[1]