|
1. 块的新增
cstring blkname;
//获取当前图形数据库
AcDbBlockTable* pBlkTbl = NULL;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
//创建新的块表记录
AcDbBlockTableRecord *pBlkTblRcd = new AcDbBlockTableRecord();
//根据块名称,添加到块表中
pBlkTblRcd->setName(blkname);
AcDbObjectId blkDefId;
pBlkTbl->add(blkDefId,pBlkTblRcd );
pBlkTbl->close();
//项块表记录中添加实体
AcGePoint3d ptStart(-10,0,0),ptEnd(10,0,0);
AcDbLine *pLine1 = new AcDbLine(ptStart,ptEnd);
ptStart.set(0,-10,0);
ptEnd.set(0,10,0);
AcDbLine *pLine2 = new AcDbLine(ptStart,ptEnd);
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId,pLine1);
pBlkTblRcd->appendAcDbEntity(entId,pLine2);
//关闭
pLine1->close();
pLine2->close();
pBlkTblRcd->close();
2. 快参照
块定义和块参照(AcDbBlockReferende) 是两个概念,块定义不一定是一个实体,而是一种对实体的描述,通过定义块获得块参照则是一种实体,图形中显示的“块”都是快参照,通过插入块获得。
在ObjectARX中块定义通过块表记录来保存,而块参照由AcDbBlockReference来来表示。既然快参照是一个实体,那么创建块参照的过程与创建一条直线似乎不应该有什么区别?事实的确如此。
cstring blkname;
//获取当前图形数据库
AcDbBlockTable* pBlkTbl = NULL;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
//查询块是否已存在
if(pBlkTbl->has(blkname))
return ;
//获取块的插入点
AcGePoint3d ptInsert(0,0,0);
//获取块表记录
AcDbObjectId blkDefId;
pBlkTbl->getAt(blkname,blkDefId);
pBlkTbl->close();
//创建快参照
AcDbBlockReference *pBlkRef = new AcDbBlockReference(ptInsert,blkDefId);
//将块参照添加到模型空间
CDwgDatabaseUtil::PostToModelSpece(pBlkRef );
pBlkRef->close();
3. 创建带有属性的块定义
cstring blkname;
//获取当前图形数据库
AcDbBlockTable* pBlkTbl = NULL;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
//创建新的块表记录
AcDbBlockTableRecord *pBlkTblRcd = new AcDbBlockTableRecord();
//根据块名称,添加到块表中
pBlkTblRcd->setName(blkname);
AcDbObjectId blkDefId;
pBlkTbl->add(blkDefId,pBlkTblRcd );
pBlkTbl->close();
//项块表记录中添加实体
AcGePoint3d ptStart(-10,0,0),ptEnd(10,0,0);
AcDbLine *pLine1 = new AcDbLine(ptStart,ptEnd);
ptStart.set(0,-10,0);
ptEnd.set(0,10,0);
AcDbLine *pLine2 = new AcDbLine(ptStart,ptEnd);
//创建一个属性
AcDbAttributeDefinition *pAtterDef = new AcDbAttributeDefinition(ptEnd,TEXT("20"),TEXT("直径"),TEXT("输入直径"));
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId,pLine1);
pBlkTblRcd->appendAcDbEntity(entId,pLine2);
pBlkTblRcd->appendAcDbEntity(entId,pAtterDef );
//关闭
pLine1->close();
pLine2->close();
pBlkTblRcd->close();
|
|