|
- 请高手帮忙看下这段代码,为啥执行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;
- }
- }
- }
复制代码 |
|