|
[code]CDwgDatabaseUtil::PlotToFile(TEXT("D:\\TEST1.pdf"), TEXT("DWG To PDF.pc3"), TEXT("A1+"), TEXT("PEACE-A3.ctb"), AcGePoint3d(1000, 100, 0), AcGePoint3d(2000, 800, 0), 100);
CDwgDatabaseUtil::PlotToFile(TEXT("D:\\TEST2.pdf"), TEXT("DWG To PDF.pc3"), TEXT("A1+"), TEXT("PEACE-A3.ctb"), AcGePoint3d(1000, 100, 0), AcGePoint3d(2000, 800, 0), 100);
CDwgDatabaseUtil::PlotToFile(TEXT("D:\\TEST3.pdf"), TEXT("DWG To PDF.pc3"), TEXT("A1+"), TEXT("PEACE-A3.ctb"), AcGePoint3d(1000, 100, 0), AcGePoint3d(2000, 800, 0), 100);
CDwgDatabaseUtil::PlotToFile(TEXT("D:\\TEST4.pdf"), TEXT("DWG To PDF.pc3"), TEXT("A1+"), TEXT("PEACE-A3.ctb"), AcGePoint3d(1000, 100, 0), AcGePoint3d(2000, 800, 0), 100);
CDwgDatabaseUtil::PlotToFile(TEXT("D:\\TEST5.pdf"), TEXT("DWG To PDF.pc3"), TEXT("A1+"), TEXT("PEACE-A3.ctb"), AcGePoint3d(1000, 100, 0), AcGePoint3d(2000, 800, 0), 100);
CDwgDatabaseUtil::PlotToFile(TEXT("D:\\TEST6.pdf"), TEXT("DWG To PDF.pc3"), TEXT("A1+"), TEXT("PEACE-A3.ctb"), AcGePoint3d(1000, 100, 0), AcGePoint3d(2000, 800, 0), 100);
bool CDwgDatabaseUtil::PlotToFile(CString strFileName, //目标文件名
CString strDeviceName, //绘图仪名字
CString strMediaName, //图纸大小
CString strSheetStyle, //打印样式
AcGePoint3d ptMin, //范围左下角点
AcGePoint3d ptMax, //范围右上角点
double dbScale //打印比例
)
{
Acad::ErrorStatus es;
AcPlPlotEngine *PlotEngine;
if (Acad::eOk != AcPlPlotFactory::createPublishEngine(PlotEngine)) return false;
//创建进度条
AcPlPlotProgressDialog *pProgress = acplCreatePlotProgressDialog(acedGetAcadFrame()->m_hWnd, false, 1);
if (pProgress)
{
pProgress->setPlotMsgString(AcPlPlotProgressDialog::kDialogTitle, TEXT("打印进度 - ") + strFileName);
pProgress->setPlotMsgString(AcPlPlotProgressDialog::kCancelJobBtnMsg, TEXT("取消打印"));
pProgress->setPlotMsgString(AcPlPlotProgressDialog::kCancelSheetBtnMsg, TEXT("取消作业"));
pProgress->setPlotMsgString(AcPlPlotProgressDialog::kSheetSetProgressCaption, TEXT("打印进度"));
pProgress->setPlotMsgString(AcPlPlotProgressDialog::kSheetProgressCaption, TEXT("打印进度"));
pProgress->setPlotProgressRange(0,100);
pProgress->onBeginPlot();
pProgress->setIsVisible(true);
}
// get a pointer to the layout manager
AcApLayoutManager *pLayoutManager = (AcApLayoutManager *)acdbHostApplicationServices()->layoutManager();
AcDbObjectId idBTR = pLayoutManager->getActiveLayoutBTRId();
AcDbBlockTableRecord *pBTR = NULL;
es = acdbOpenObject(pBTR, idBTR, AcDb::kForRead);
// We want to instantiate our custom AcDbPlotSettings object, and inherit the
// properties from the active layout.
AcDbObjectId idLayout = pBTR->getLayoutId();
AcDbLayout *pLayout = NULL;
es = acdbOpenObject(pLayout, idLayout, AcDb::kForRead);
AcDbPlotSettings *pPlotSettings = new AcDbPlotSettings(pLayout->modelType());
es = pPlotSettings->copyFrom(pLayout);
pLayout->close();
pBTR->close();
AcDbPlotSettingsValidator *pPlotSettingsValidator = acdbHostApplicationServices()->plotSettingsValidator();
if (pPlotSettingsValidator == NULL) return false;
//设置打印的详细参数
pPlotSettingsValidator->refreshLists (pPlotSettings); // Refresh the layout lists in order to use it
es = pPlotSettingsValidator->setPlotCfgName(pPlotSettings, strDeviceName); //设置绘图仪
es = pPlotSettingsValidator->setPlotWindowArea(pPlotSettings, ptMin.x, ptMin.y, ptMax.x, ptMax.y); //设置打印范围
es = pPlotSettingsValidator->setPlotOrigin(pPlotSettings, ptMin.x, ptMin.y); //设置origin
es = pPlotSettingsValidator->setPlotCentered(pPlotSettings, true); //是否居中打印
es = pPlotSettingsValidator->setPlotType(pPlotSettings, AcDbPlotSettings::kExtents); //打印类型
es = pPlotSettingsValidator->setStdScale(pPlotSettings, dbScale); //比例
//es = pPlotSettingsValidator->setStdScaleType (pLayout, AcDbPlotSettings::StdScaleType::kScaleToFit);
// we have to close the layout here because the last parameter of
// findLayoutNamed is true, leave layout open
es = PlotEngine->beginPlot(pProgress, NULL);
AcPlPlotInfo plotInfo;
plotInfo.setLayout(idLayout);
plotInfo.setOverrideSettings(pPlotSettings);
AcPlPlotConfig *pPlotConfig = NULL;
es = acplPlotConfigManagerPtr()->setCurrentConfig(pPlotConfig, strDeviceName);
pPlotConfig->setPlotToFile(true);
pPlotConfig->refreshMediaNameList();
plotInfo.setDeviceOverride(pPlotConfig);
//开始打印
AcPlPlotInfoValidator plotInfoValidator;
AcPlPlotPageInfo pageInfo;
plotInfoValidator.setMediaMatchingPolicy(AcPlPlotInfoValidator::kMatchEnabled);
plotInfoValidator.validate(plotInfo);
es = PlotEngine->beginDocument(plotInfo, acDocManager->curDocument()->fileName(), NULL, 1, true, strFileName);
es = PlotEngine->beginPage(pageInfo, plotInfo, true);
es = PlotEngine->beginGenerateGraphics();
PlotEngine->endGenerateGraphics();
PlotEngine->endPage();
PlotEngine->endDocument();
PlotEngine->endPlot();
PlotEngine->destroy();
PlotEngine = NULL;
pProgress->destroy();
pProgress = NULL;
delete pPlotSettings;
pPlotSettings = NULL;
return true;
}[/code] |
|