|
- #include "dbmain.h"
- #include "dbdict.h"
- // 创建一个新的块定义
- void CreateBlockDefinition(AcDbDatabase* pDb, const char* blockName, AcGePoint3d basePoint)
- {
- // 打开或创建块字典
- AcDbDictionary *pBlockDict;
- Acad::ErrorStatus es = pDb->getSymbolTable(pBlockDict, AcDb::kForWrite, AcDb::kCreateIfNotFound, AcRxClass::cast<AcDbBlockTable>());
- if (es != Acad::eOk) return;
- // 创建新块记录
- AcDbBlockTableRecord* pNewBlock = new AcDbBlockTableRecord();
- es = pNewBlock->setName(blockName);
- if (es != Acad::eOk)
- {
- delete pNewBlock;
- return;
- }
- // 设置块基点
- pNewBlock->setBasePoint(basePoint, false);
- // 将新块记录添加至块字典
- es = pBlockDict->upgradeOpen();
- if (es == Acad::eOk)
- {
- es = pBlockDict->setAt(blockName, pNewBlock, AcDb::kTrue);
- pBlockDict->close();
- }
- // 关闭并提交新块记录
- pNewBlock->close();
- if (es != Acad::eOk)
- {
- pNewBlock->erase();
- }
- }
- // 示例使用
- AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
- AcGePoint3d origin(0, 0, 0);
- CreateBlockDefinition(pDb, "MyBlock", origin);
复制代码 |
|