- 积分
- 180
- 明经币
- 个
- 注册时间
- 2011-11-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-11-12 12:04:55
|
显示全部楼层
这个问题我已解决,给你一段小代码
void BindXref2()
{
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
BindXref2(pDb);
}
void BindXref2(AcDbDatabase *pDb)
{
Acad::ErrorStatus es;
AcDbObjectIdArray objIdArr;
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord * pBlockTableRecord;
es = pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk) return;
AcDbBlockTableIterator *pBlockTableIterator;
es = pBlockTable->newIterator(pBlockTableIterator);
if (es != Acad::eOk) {
pBlockTable->close();
return;
}
pBlockTable->close();
//遍历一个图块表中所有图块
for (; !pBlockTableIterator->done();
pBlockTableIterator->step(true,true)) //skipDeleted = true
{
es = pBlockTableIterator->getRecord (pBlockTableRecord, AcDb::kForRead);
if (es != Acad::eOk) continue;
if(pBlockTableRecord->isFromExternalReference() == Adesk::kTrue)
{
objIdArr.append(pBlockTableRecord->objectId( )); //记录外部参照
}
pBlockTableRecord->close();
}//---for
delete pBlockTableIterator;
if (objIdArr.length() > 0){
Do_BindXref2(pDb, objIdArr);
}
}
//===================================================================================
void Do_BindXref2(AcDbDatabase *pDb, AcDbObjectIdArray& objIdArr)
{
if (objIdArr.length()==0) {
return;
}
Acad::ErrorStatus es;
long i;
for(i=0; i<objIdArr.length(); i++)
{
//打开这个外部参照图块物体
AcDbObject *pObj;
AcDbBlockTableRecord *pBlkRcd;
es = acdbOpenObject(pObj, objIdArr[i], AcDb::kForWrite);
if (es != Acad::eOk) {
continue;
}
pBlkRcd = AcDbBlockTableRecord::cast(pObj);
if (pBlkRcd == NULL) {
pObj->close();
continue;
}
TCHAR *Blkname;
es = pBlkRcd->getName(Blkname);
pObj->close();
//开始替换外部参照
es = acedXrefReload(Blkname,true,pDb); //必须先Reload,否则pDb为非当前显式打开文档时不成功或崩溃
if(es == Acad::eOk){
es = acedXrefBind(Blkname,false,true,pDb); //必须先关闭这个块表
}
}
} |
|