CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

使用绘图 API

2023-1-1 01:38| 发布者: admin| 查看: 318| 评论: 0|来自: AutoCAD

应用程序可以选择使用绘图 API 配置时功能、打印时功能或两者。它们还可以包括多页文档、打印到文件、错误处理和覆盖默认打印进度对话框的规定。

注意:

每当通过绘图 API 访问绘图引擎时,如果 BACKGROUNDPLOT 系统变量设置为 0,系统将在前台进行绘图,如果 BACKGROUNDPLOT 系统变量设置为 1、2 或 3,则系统将在后台进行绘制。

使用基本的配置时和打印时 API

  1. 获取布局的 ID 并使其在编辑器中处于活动状态。(布局必须在步骤 7 中调用的时间之前处于活动状态。beginPage()
  2. 创建一个对象并在其上设置布局 ID。AcPlPlotInfo
  3. 实现 UI 以创建对象(可选)。AcDbPlotSettings
  4. 使用向对象传递指向绘图设置对象(如果有)的指针。AcPlPlotInfoAcPlPlotInfo::setOverrideSettings()
  5. 调用绘图信息对象。AcPlPlotInfoValidator::validate()

    这将验证替代是否与布局设置兼容。例如,图纸空间和模型空间设置是互斥的,指定的设备必须存在。

  6. 创建一个对象使用器。AcPlPlotEngineAcPlPlotFactory::createPreviewEngine()AcPlPlotFactory::createPublishEngine()
  7. 在引擎上调用以下函数:
  8. beginPlot()
  9. beginDocument()
  10. beginPage()
  11. beginGenerateGraphics()
  12. endGenerateGraphics()
  13. endPage()
  14. endDocument()
  15. endPlot()

以下代码演示了 API 和默认打印进度对话框的基本用法,“打印进度”对话框中对此进行了进一步讨论。

AcPlPlotEngine* pEngine = NULL;
if(Acad::eOk==AcPlPlotFactory::createPublishEngine(pEngine))
{
    // Here is the progress dialog for the current plot process...
    AcPlPlotProgressDialog *pPlotProgDlg=acplCreatePlotProgressDialog(
        acedGetAcadFrame()->m_hWnd,false,1);
    pPlotProgDlg->setPlotMsgString(
        AcPlPlotProgressDialog::PlotMSGIndex::kDialogTitle,
        "Plot API Progress");
    pPlotProgDlg->setPlotMsgString(
        AcPlPlotProgressDialog::PlotMSGIndex::kCancelJobBtnMsg,
        "Cancel Job");
    pPlotProgDlg->setPlotMsgString(
        AcPlPlotProgressDialog::PlotMSGIndex::kCancelSheetBtnMsg,
        "Cancel Sheet");
    pPlotProgDlg->setPlotMsgString(
        AcPlPlotProgressDialog::PlotMSGIndex::kSheetSetProgressCaption,
        "Job Progress");
    pPlotProgDlg->setPlotMsgString(
        AcPlPlotProgressDialog::PlotMSGIndex::kSheetProgressCaption,
        "Sheet Progress");
    pPlotProgDlg->setPlotProgressRange(0,100);
    pPlotProgDlg->onBeginPlot();
    pPlotProgDlg->setIsVisible(true);
    es = pEngine->beginPlot(pPlotProgDlg);
    AcPlPlotPageInfo pageInfo;
    // Used to describe how the plot is to be made.
    AcPlPlotInfo plotInfo; 
    // First, set the layout to the specified layout 
    // (which is the current layout in this sample).
    plotInfo.setLayout(layoutId);// This is required.
    // Now, override the layout settings with the plot settings 
    // we have been populating.
    plotInfo.setOverrideSettings(pPlotSettings);
    // We need to validate these settings.
    AcPlPlotInfoValidator validator;
    validator.setMediaMatchingPolicy(
        AcPlPlotInfoValidator::MatchingPolicy::kMatchEnabled);
    es = validator.validate(plotInfo);
    // Begin document.  The version we call is dependent 
    // on the plot-to-file status.
    const char *szDocName=acDocManager->curDocument()->fileName();
    if(m_bPlotToFile)
        es = pEngine->beginDocument(plotInfo, szDocName, 
            NULL, 1, true, m_csFilename);
    else
        es = pEngine->beginDocument(plotInfo, szDocName);
    // Follow through sending commands to the engine, 
    // and notifications to the progress dialog.
    pPlotProgDlg->onBeginSheet();
    pPlotProgDlg->setSheetProgressRange(0, 100);
    pPlotProgDlg->setSheetProgressPos(0);
    es = pEngine->beginPage(pageInfo, plotInfo, true);
    es = pEngine->beginGenerateGraphics();
    es = pEngine->endGenerateGraphics();
    es = pEngine->endPage();
    pPlotProgDlg->setSheetProgressPos(100);
    pPlotProgDlg->onEndSheet();
    pPlotProgDlg->setPlotProgressPos(100);
    es = pEngine->endDocument();
    es = pEngine->endPlot();
    // Destroy the engine 
    pEngine->destroy();
    pEngine = NULL;
    // and the progress dialog.
    pPlotProgDlg->destroy();
else
    // Ensure the engine is not already busy...
    AfxMessageBox("Plot Engine is Busy...");
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 16:18

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部