|
发现autocad的打印需要把环境变量BACKGROUNDPLOT设置为0,即前台打印
void PlotDwgToPdf(std::shared_ptr<AcDbPlotSettings>& ptrPlotSettings)
{
struct resbuf rbBackGroundPlot;
acedGetVar(_T("BACKGROUNDPLOT"), &rbBackGroundPlot);
if (rbBackGroundPlot.restype == RTSHORT && rbBackGroundPlot.resval.rint != 0)
{
int nOld = rbBackGroundPlot.resval.rint;
rbBackGroundPlot.resval.rint = 0;
acedSetVar(_T("BACKGROUNDPLOT"), &rbBackGroundPlot);
rbBackGroundPlot.resval.rint = nOld;
}
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, L"Plot API Progress");
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::PlotMSGIndex::kCancelJobBtnMsg, L"Cancel Job");
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::PlotMSGIndex::kCancelSheetBtnMsg, L"Cancel Sheet");
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::PlotMSGIndex::kSheetSetProgressCaption, L"Job Progress");
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::PlotMSGIndex::kSheetProgressCaption, L"Sheet Progress");
pPlotProgDlg->setPlotProgressRange(0, 100);
pPlotProgDlg->onBeginPlot();
pPlotProgDlg->setIsVisible(true);
if (m_PlotSettingInfo.m_vecBlockInfo4Plot.size())
{
int nDwgCount = m_PlotSettingInfo.m_vecBlockInfo4Plot.size();
for (int num = 0; num < m_PlotSettingInfo.m_vecBlockInfo4Plot.size(); num++)
{
if (pPlotProgDlg->isPlotCancelled() || pPlotProgDlg->isSheetCancelled())
{
break;
}
CString csStatus;
csStatus.Format(_T("正在打印%d/%d..."), num + 1, nDwgCount);
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::PlotMSGIndex::kSheetName, csDstPdf);
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::PlotMSGIndex::kStatus, csStatus);
SetPlotSettingValidator(ptrPlotSettings, m_PlotSettingInfo.m_vecBlockInfo4Plot[num]);
SetPlotInfo(m_PlotSettingInfo.m_LayoutId, ptrPlotSettings.get());
DoPlot(pPlotProgDlg, pEngine, true, csDstPdf);
int nProgressPercent = (num + 1) * 100 / nDwgCount;
pPlotProgDlg->setPlotProgressPos(100);
}
}
// Destroy the engine
pEngine->destroy();
pEngine = NULL;
// and the progress dialog.
pPlotProgDlg->destroy();
pPlotProgDlg = NULL;
}
else
{
// Ensure the engine is not already busy...
AfxMessageBox(L"Plot Engine is Busy...");
}
acedSetVar(_T("BACKGROUNDPLOT"), &rbBackGroundPlot);
} |
|