- UID
- 737382
- 积分
- 386
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2014-9-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 why1025 于 2017-7-2 10:21 编辑
我自己修改的帮助文档的打印的例子,编译通过,但是加载执行cad崩溃
static void PlotAPI_plotPreview(void)
{
Acad::ErrorStatus es;
AcAxDocLock lock;
AcDbPlotSettingsValidator* pPSV=NULL;
//AcDbPlotSettings *pPlotSettings;
//AcDbPlotSettings* pPlotSetting = (AcDbPlotSettings*)pLayout;
BOOL m_bFit=FALSE;
double m_Scale=0;
BOOL m_Landscape=FALSE;
AcDbObjectId layoutId;
//CComPtr<IAsdkPlotNotifySink> pPlotSink=NULL;
/*, m_Scale(0)
, m_Landscape(FALSE)
, m_CurrentDevice(_T(""))
, pPSV(NULL)
, m_bFit(FALSE)
, m_Background(FALSE)
, m_bPlotToFile(FALSE)
, m_csFilename(_T(""))
,dwAppCF(0)
,dwAppObj(0)
,pPlotSink(NULL)*/
/*CComboBox m_Devices;
CComboBox m_Media;
double m_Scale;
AcDbObjectId layoutId;
BOOL m_Landscape;
CString m_CurrentDevice;
CString m_CurrentMedia;
AcDbPlotSettingsValidator* pPSV;
AcDbPlotSettings *pPlotSettings;
void CalcExtents(void);
BOOL m_bFit;
BOOL m_Background;
BOOL m_bPlotToFile;
CString m_csFilename;
DWORD dwAppCF;*/
//DWORD dwAppObj;
AcApLayoutManager *pLayMan = NULL;
pLayMan=(AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
//get the active layout
AcDbLayout *pLayout = pLayMan->findLayoutNamed(pLayMan->findActiveLayout(TRUE),TRUE);
AcDbPlotSettings* pPlotSettings = (AcDbPlotSettings*)pLayout;
es=pPSV->setPlotType(pPlotSettings,AcDbPlotSettings::kExtents);
// Set the Scale...
if (m_bFit)
{
es = pPSV->setUseStandardScale(pPlotSettings,Adesk::kTrue);
es = pPSV->setStdScaleType(pPlotSettings,AcDbPlotSettings::kScaleToFit);
}
else // Choose to use this custom scale...
{
es=pPSV->setUseStandardScale(pPlotSettings,Adesk::kFalse);
es=pPSV->setCustomPrintScale(pPlotSettings,m_Scale,1);
}
es=pPSV->setPlotCentered(pPlotSettings,true);
acedGetAcadFrame()->ShowWindow(SW_SHOW);
acedGetAcadFrame()->SetFocus();
//下面这句注释掉了,编译不过
/*ShowWindow(SW_HIDE);
if(pPlotSink)
pPlotSink->put_Visible(FALSE);*/
AcPlPlotEngine* pEngine = NULL;
if(Acad::eOk==AcPlPlotFactory::createPreviewEngine(pEngine))
{
pEngine->beginPlot(NULL);
AcPlPlotPageInfo pageInfo;
AcPlPlotInfo plotInfo;
plotInfo.setLayout(layoutId);
plotInfo.setOverrideSettings(pPlotSettings);
AcPlPlotInfoValidator validator;
validator.setMediaMatchingPolicy(AcPlPlotInfoValidator::kMatchEnabled);
es = validator.validate(plotInfo);
const TCHAR *szDocName=acDocManager->curDocument()->fileName();
es = pEngine->beginDocument(plotInfo, szDocName);
es = pEngine->beginPage(pageInfo, plotInfo, true);
es = pEngine->beginGenerateGraphics();
es = pEngine->endGenerateGraphics();
es = pEngine->endPage();
es = pEngine->endDocument();
es = pEngine->endPlot();
pEngine->destroy();
pEngine = NULL;
}
else
AfxMessageBox(_T("Plot Engine is Busy..."));
//下面这句注释掉了,编译不过
/*ShowWindow(SW_SHOW);
if(pPlotSink)
pPlotSink->put_Visible(TRUE);*/
}
static void PlotAPI_bPlot(void)
{
Acad::ErrorStatus es;
AcAxDocLock lock;
AcApLayoutManager *pLayMan = NULL;
pLayMan=(AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
//get the active layout
AcDbLayout *pLayout = pLayMan->findLayoutNamed(pLayMan->findActiveLayout(TRUE),TRUE);
AcDbPlotSettings* pPlotSettings = (AcDbPlotSettings*)pLayout;
AcDbPlotSettingsValidator* pPSV=NULL;
BOOL m_bFit=FALSE;
double m_Scale=0;
BOOL m_Landscape=FALSE;
AcDbObjectId layoutId;
es=pPSV->setPlotType(pPlotSettings,AcDbPlotSettings::kExtents);
// Set the Scale...
if (m_bFit)
{
es = pPSV->setUseStandardScale(pPlotSettings,Adesk::kTrue);
es = pPSV->setStdScaleType(pPlotSettings,AcDbPlotSettings::kScaleToFit);
}
else // Choose to use this custom scale...
{
es=pPSV->setUseStandardScale(pPlotSettings,Adesk::kFalse);
es=pPSV->setCustomPrintScale(pPlotSettings,m_Scale,1);
}
// Specify that we want our plot centered by AutoCAD...
es=pPSV->setPlotCentered(pPlotSettings,true);
// Create a publish engine, and send the plot through...
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::kDialogTitle,_T("Plot API Progress"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kCancelJobBtnMsg,_T("Cancel Job"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kCancelSheetBtnMsg,_T("Cancel Sheet"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kSheetSetProgressCaption,_T("Job Progress"));
pPlotProgDlg->setPlotMsgString(AcPlPlotProgressDialog::kSheetProgressCaption,_T("Sheet Progress"));
pPlotProgDlg->setPlotProgressRange(0,100);
pPlotProgDlg->onBeginPlot();
pPlotProgDlg->setIsVisible(true);
es = pEngine->beginPlot(pPlotProgDlg);
AcPlPlotPageInfo pageInfo;
AcPlPlotInfo plotInfo; // Used to describe how the plot is to be made
// 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::kMatchEnabled);
es = validator.validate(plotInfo);
// Begin document. The version we call is dependent on the plot-to-file status.
const TCHAR *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(_T("Plot Engine is Busy..."));
} |
|