Table Templetes 的代码示例
下面是实现表模板保存和加载的一种方法, // Create a table template from a table, and create a table style
to hold the template.
void createTemplate()
{
// Select a table
ErrorStatus es;
AcDbTable *pTbl = NULL;
if(NULL == (pTbl = AcDbTable::cast(selectEntity(_T("\nSelect a table: ")))))
acutPrintf(ACRX_T("\nSelected entity was not a table!"));
static ACHAR sNameOfMyTableTemplate[MAX_PATH] = ACRX_T("MyTableTemplate");
static ACHAR sNameOfMyTableStyle[MAX_PATH] = ACRX_T("MyTableStyle");
AcDbTableTemplate* pTblTpl = new AcDbTableTemplate();
// We skip its content here.
es = pTblTpl->capture(pTbl, AcDb::kTableCopySkipContent);
es = pTblTpl->setName(sNameOfMyTableTemplate);
AcDbTableStyle* pTblSty = new AcDbTableStyle();
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
assert(pDb);
// If a style with the name is already in the TableStyleDictionary, remove it.
AcDbDictionary *pDict = NULL;
es = acdbHostApplicationServices()->workingDatabase()->getTableStyleDictionary(pDict,AcDb::kForRead);
// Check if the Table Style is already there.
if(pDict->has(sNameOfMyTableStyle))
{
es = pDict->upgradeOpen();
es = pDict->remove(sNameOfMyTableStyle);
}
// Post the table style to DB and then set the table template to it.
AcDbObjectId idTS;
es = pDict->upgradeOpen();
if(Acad::eOk != (es = pDict->setAt(sNameOfMyTableStyle,pTblSty,idTS)))
{
pDict->close();
delete pTblSty;
delete pTblTpl;
es = pTbl->close();
acutPrintf(ACRX_T("\nUnable to add new Table Style"));
return;
}
es = pDict->close();
assert(es == Acad::eOk);
// Set the new template to the table.
AcDbObjectID id;
es = pTblSty->setTemplate(pTblTpl, AcDb::kMergeCellStyleNone, id);
if( es != Acad::eOk )
{
delete pTblTpl;
pTblSty->close();
pTbl->close();
acutPrintf(ACRX_T("\nError in setting data table template!"));
return;
}
// Clean up.
es = pTblSty->close();
es = pTblTpl->close();
es = pTbl->close();
}
父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-31 02:13
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.