arx二次开发调用打印流程说明
Plot Settings ValidationPlot APIMulti-page Documents
Autodesk ObjectARX for AutoCAD 2020: Developer’s Guide > Basic Interaction with AutoCAD > Plot API >
Using the Plot API
Applications may choose to use the plot API configuration-time capability, the plot-time capability, or both. They can also include provisions for multi-page documents, plotting to a file, error handling, and overriding the default plot progress dialog box.
Note
Any time the plot engine is accessed through the plot API, the system will plot in the foreground if the BACKGROUNDPLOT system variable is set to 0, and in the background if the BACKGROUNDPLOT system variable is set to 1,2, or 3.
To use the basic configuration-time and plot-time APIs
- Get the ID of the layout and make it active in the editor. (The
layout must be active by the time beginPage() is called in step 7.) - Create an AcPlPlotInfo object and set the layout ID on it.
- Implement a UI to create an AcDbPlotSettings object (optional).
- Pass the AcPlPlotInfo object a pointer to the plot settings object
(if there is one) using AcPlPlotInfo::setOverrideSettings(). - Call AcPlPlotInfoValidator::validate() on the plot info object.
- This verifies that the overrides are compatible with the layout
settings. For example, paper space and model space settings are
mutually exclusive and the specified device must exist. - Create an AcPlPlotEngine object using
AcPlPlotFactory::createPreviewEngine() or
AcPlPlotFactory::createPublishEngine(). - Call the following functions on the engine:
beginPlot()
beginDocument()
beginPage()
beginGenerateGraphics()
endGenerateGraphics()
endPage()
endDocument()
endPlot()
The following code illustrates a basic use of the API and the default plot progress dialog box, which is discussed further in Plot Progress Dialog Box.
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...");
}