- UID
- 3684
- 积分
- 844
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-4-8
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
块的建立:
BOOL CreatBlock(AcDbObjectIdArray objIds, char* pBlockName)
{
if (objIds.isEmpty()) return FALSE;
AcDbObject* pObj;
AcDbObjectIdArray objList;
AcDbObjectId objId,owner_Id = AcDbObjectId::kNull;
for (int i=0;objIds.length()>i;i++)
{
objId=objIds.at(i);
if (acdbOpenObject(pObj, objId, AcDb::kForRead)!=Acad::eOk) return FALSE;
if (pObj->ownerId() == owner_Id)
objList.append(objId);
else if (i == 0)
{
owner_Id = pObj->ownerId();
objList.append(objId);
}
pObj->close();
}
AcDbBlockTable *pBlockTable;
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForWrite);
AcDbBlockTableRecord *pBlockTableRec=new AcDbBlockTableRecord();
// if (pBlockName=="")//匿名块的建立?no setAnonymous();
pBlockTableRec->setName(pBlockName);
pBlockTable->add(pBlockTableRec);//BlockTableRecord加入BlockTable
pBlockTableRec->close();
AcDbObjectId cur_blockId;//指向当前的bock_table_record
pBlockTable->getAt(pBlockName, cur_blockId);
pBlockTable->close();
AcDbIdMapping idMap;
acdbCurDwg() ->deepCloneObjects(objList, cur_blockId, idMap);
return TRUE;
}
以上相当于在块定义对话框中选择了保留项.现在块就存在于AcDbBlockTable 中,对他的操作就简单了
插入块:
AcDbObjectId cur_blockId;
AcDbEntity* pblock;
AcDbBlockTable *pBlockTable;
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForWrite);//得到块表的指针
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(pBlockName,cur_blockId);//得到块的id
acdbOpenObject(pblock,cur_blockId,AcDb::kForRead);
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
pBlockTableRecord->appendAcDbEntity(returnId,pblock);
pblock->close();
return TRUE;
//以上的思路是得到块的指针pblock,通appendAcDbEntity把块加入ACDB_MODEL_SPACE,
//但是这是错误的,你会发现pblock同时存在于ACDB_MODEL_SPACE,pBlockName中,
//////////////////////////////////////////////////////////////
AcDbObjectId cur_blockId,BlockTableId;
AcDbBlockTable *pBlockTable;
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForWrite);//得到块表的指针
pBlockTable->getAt(pBlockName,cur_blockId);//得到块的id
pBlockTable->getAt(ACDB_MODEL_SPACE, BlockTableId);
pBlockTable->close();
AcDbObjectIdArray objList;
objList.append(cur_blockId);
AcDbIdMapping idMap;
//
acdbCurDwg() ->deepCloneObjects(objList, BlockTableId, idMap);
return TRUE;
//以上是根据建立块的反思路进行的,首先得到块的id(cur_blockId),利用deepCloneObjects,加入ACDB_MODEL_SPACE,
//当然也会迭代块内的物体,放入objList,再利用deepCloneObjects,加入ACDB_MODEL_SPACE,(我没式过).
//以上方法也没成功,请高手指导指导. |
|