得到块定义id(通过图纸、块名和数据库指针;如果数据库中没有该块定义,就从目标图纸
bool PhdArxBlock::GetBlkDefId(AcDbObjectId& idBlkDef, LPCTSTR szDwgPath, LPCTSTR szBlkName, AcDbDatabase* pDb /*= acdbCurDwg()*/) const{
AcDbBlockTableRecordPointer pInsertBlkTblRcd(szBlkName, pDb, AcDb::kForRead);
if (Acad::eOk == pInsertBlkTblRcd.openStatus())
{
idBlkDef = pInsertBlkTblRcd->objectId();//当前数据库存在该块,返回该块定义id
return true;
}
//打开图纸
AcDbDatabase* pDbDwg = new AcDbDatabase(false);
std::unique采用ptr<AcDbDatabase> apDbDwg(pDbDwg);
//Acad::ErrorStatus es = apDbDwg->readDwgFile(szDwgPath, 采用SH采用DENYNO);//zrx2010
Acad::ErrorStatus es = apDbDwg->readDwgFile(szDwgPath, AcDbDatabase::kForReadAndAllShare);//arx2017
if (Acad::eOk != es)
return false;
//从图纸数据库得到块定义id
AcDbObjectId idTempBlkDef = AcDbObjectId::kNull;
if (!GetBlkDefId(idTempBlkDef, szBlkName, apDbDwg.get()))
return false;
//将图纸数据库中的块定义拷贝到pDb数据库中
if (!g采用ArxDatabase->DbCopyOfBlock(apDbDwg.get(), idTempBlkDef, pDb, szBlkName, idBlkDef))
return false;
return true;
}
页:
[1]