悬赏已过期 后悬赏过期
悬赏

CAD采用自定义格式批量打印图片,会在打印几千张后卡住

邀请:

debug状态下, 发现卡在“plotEngine.EndDocument(null);”

 

[CommandMethod("PNGTest", CommandFlags.Session)]
public void PNGTest()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    // 打印样式表:zwcad.ctb
    string styleSheetName = "zwcad.ctb";

    string deviceName = "ZWCAD Virtual PNG Plotterfd05d551.pc5";
    string NewPaperName = string.Format("UserDefinedMetric ({0}.00 x {1}.00 像素)", 200, 200);
    for (int i = 0;i<10000;i++)
    {
        string outputName = string.Format("{0}\\{1}.png", Path.GetDirectoryName(db.Filename), i);
        Print(outputName, styleSheetName, deviceName, NewPaperName);
    }
}

private void Print(string outputFilePath, string styleSheetName,string deviceName,string NewPaperName)
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        PlotConfigManager.RefreshList(RefreshCode.All);
        // 获取DWG to PDF.pc3打印机
        PlotConfig plotConfig = PlotConfigManager.SetCurrentConfig(deviceName);
        plotConfig.RefreshMediaNameList();
        // 将打印机的PlotToFile属性设置为true
        plotConfig.IsPlotToFile = true;

        PlotSettings plotSettings = new PlotSettings(true);
        PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;

        // 配置打印设置和打印信息
        plotSettingsValidator.SetUseStandardScale(plotSettings, true);
        plotSettingsValidator.SetZoomToPaperOnUpdate(plotSettings, true);
        // 设置布满图纸
        plotSettingsValidator.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
        // 设置旋转角度
        plotSettingsValidator.SetPlotRotation(plotSettings, PlotRotation.Degrees000);


        // 设置设备名称和图纸名称
        plotSettingsValidator.SetCanonicalMediaName(plotSettings, NewPaperName);
        // 设置打印样式表
        plotSettingsValidator.SetCurrentStyleSheet(plotSettings, styleSheetName);
        // 如果传入的有范围,则按照具体范围去打印
        plotSettingsValidator.SetPlotType(plotSettings, ZwSoft.ZwCAD.DatabaseServices.PlotType.Extents);

        // 设置打印居中
        plotSettingsValidator.SetPlotCentered(plotSettings, true);
        // 设置着色打印选项
        plotSettings.ShadePlot = PlotSettingsShadePlotType.AsDisplayed;

        //验证打印信息PlotInfo
        PlotInfoValidator plotInfoValidator = new PlotInfoValidator();
        PlotInfo plotInfo = new PlotInfo();

        LayoutManager manager = LayoutManager.Current;
        Layout layout = acTrans.GetObject(manager.GetLayoutId(manager.CurrentLayout), OpenMode.ForRead) as Layout;
        plotInfo.Layout = layout.ObjectId;

        plotInfo.OverrideSettings = plotSettings;
        plotInfo.DeviceOverride = plotConfig;
        plotInfo.ValidatedConfig = plotConfig;

        plotInfoValidator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
        plotInfoValidator.Validate(plotInfo);

        // 使用PlotEngine对象开始打印
        using (PlotEngine plotEngine = PlotFactory.CreatePublishEngine())
        {
            // 执行打印操作
            plotEngine.BeginPlot(null, null);
            plotEngine.BeginDocument(plotInfo, acDoc.Name, null, 1, true, outputFilePath);

            PlotPageInfo pageInfo = new PlotPageInfo();
            plotEngine.BeginPage(pageInfo, plotInfo, true, null);
            plotEngine.BeginGenerateGraphics(null);
            plotEngine.EndGenerateGraphics(null);
            plotEngine.EndPage(null);
            plotEngine.EndDocument(null);
            plotEngine.EndPlot(null);
        }
    }
}
1
收藏0
分享
您的回答

回答

默认排序 时间排序
图片审查中...
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
复制链接
微信扫码
已复制到剪贴板