- UID
- 772294
- 积分
- 14
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2017-11-15
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
请高手帮忙看下这段代码,为啥执行pPlot->PlotToFile(w_str.c_str(), szPrinterPath);就会异常
根本就不能打印出pdf图片。在线等
/*
*区域打印
*
*/
void Cplot::OnPrint(std::string strPath,int size,bool direc,AcGePoint2d ptStart,AcGePoint2d ptEnd)
{
acDocManager->lockDocument(acDocManager->curDocument());
// Use ActiveX interface to get the application object
IAcadApplicationPtr pAcad = acedGetAcadWinApp()->GetIDispatch(TRUE);
//get the path to plotter configuration
_bstr_t szPrinterPath;
szPrinterPath = pAcad->Preferences->GetFiles()->GetPrinterConfigPath() + _bstr_t("\\DWG To PDF.pc3");//_T("DWG To PDF.pc3");//_T("DWF6 eplot.pc3");
// get the current database
//AcDbDatabase *curDocDB = acdbHostApplicationServices()->workingDatabase();
// get a pointer to the layout manager
AcApLayoutManager *pLayoutManager = (AcApLayoutManager *)acdbHostApplicationServices()->layoutManager();
const ACHAR *layoutName = pLayoutManager->findActiveLayout (true);
// get the current layout
AcDbLayout *pLayout = pLayoutManager->findLayoutNamed (layoutName, true);
// if we got it ok
if (pLayout != NULL)
{
Acad::ErrorStatus es;
// get the plotsetttings class
AcDbPlotSettingsValidator *pPlotSettingsValidator = acdbHostApplicationServices()->plotSettingsValidator();
// if we got it ok
if (pPlotSettingsValidator != NULL)
{
// Refresh the layout lists in order to use it
pPlotSettingsValidator->refreshLists (pLayout);
// change the current layout plotter
es = pPlotSettingsValidator->setPlotCfgName (pLayout, szPrinterPath);
// set the window to plot as the extents of the drawing
ACHAR* m_Name_2 = _T("ISO_A2_(420.00_x_594.00_MM)");//图纸名称
ACHAR* m_Name_3 = _T("ISO_A3_(297.00_x_420.00_MM)");//图纸名称
ACHAR* m_Name_4 = _T("ISO_A4_(210.00_x_297.00_MM)");//图纸名称
ACHAR* m_mediaName;
if (size == 2){
m_mediaName = m_Name_2;
}
else if (size == 3){
m_mediaName = m_Name_3;
}
else if (size ==4){
m_mediaName = m_Name_4;
}
es = pPlotSettingsValidator->setCanonicalMediaName(pLayout,m_mediaName);//设置图纸尺寸
es = pPlotSettingsValidator->setPlotWindowArea(pLayout,ptStart.x,ptStart.y,ptEnd.x,ptEnd.y);//设置打印范围,超出给范围的将打不出来
es = pPlotSettingsValidator->setPlotOrigin(pLayout,ptStart.x,ptStart.y);//设置打印原点
es = pPlotSettingsValidator->setPlotType(pLayout,AcDbPlotSettings::kWindow);//设置打印范围为窗口
es = pPlotSettingsValidator->setCurrentStyleSheet(pLayout,_T("acad.ctb"));//设置打印样式表
es = pPlotSettingsValidator->setPlotCentered(pLayout,true);//是否居中打印
es = pPlotSettingsValidator->setUseStandardScale(pLayout,true);//设置是否采用标准比例
es = pPlotSettingsValidator->setStdScaleType(pLayout,AcDbPlotSettings::kScaleToFit);//布满图纸
PlotRotation m_direc;
if (direc) m_direc = AcDbPlotSettings::k0degrees; //纵向
else m_direc = AcDbPlotSettings::k90degrees;//横向
es = pPlotSettingsValidator->setPlotRotation(pLayout,m_direc);//设置打印方向
}
pLayout->close ();
// get the current document
IAcadDocumentPtr pDoc = pAcad->GetActiveDocument();
//pDoc->SetVariable("BACKGROUNDPLOT",0);
//pDoc->ActiveLayout->RefreshPlotDeviceInfo();
// create a plot object
IAcadPlotPtr pPlot = pDoc->GetPlot();
// lets plot
std::wstring w_str = CStringUtil::s2ws(strPath);
try
{
pPlot->PlotToFile(w_str.c_str(), szPrinterPath);
acDocManager->unlockDocument(acDocManager->curDocument());
}
catch (...)
{
acDocManager->unlockDocument(acDocManager->curDocument());
AfxMessageBox(_T("打印任务繁忙,请稍后再试!"));
return;
}
}
}
|
|