CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

相关分类

表神庙的代码示例

2022-12-31 20:17| 发布者: admin| 查看: 273| 评论: 0|来自: AutoCAD

以下是实现表寺庙保存和加载的一种方法,

// 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();
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:20

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部