|
[code]得到块定义中的所有实体id(通过块名和数据库指针)
//************************************
// Summary: 得到块定义中的所有实体id(通过块名和数据库指针)
// Parameter:
// arrid - 输出块定义中所有实体id集合
// szBlkTblRcdName - 输入块表记录名(块定义名、块名)(模型空间的名字是:ACDB_MODEL_SPACE)
// pDb - 输入块定义所在数据库指针
// Return:
// Update Time: 2021-7-16 16:06:42 peihaodong
//************************************
bool PhdArxBlock::GetAllEntId(AcDbObjectIdArray& arrid, LPCTSTR szBlkTblRcdName, AcDbDatabase* pDb /*= acdbCurDwg()*/) const
{
AcDbBlockTableRecordPointer pBlkTblRcd(szBlkTblRcdName, pDb, AcDb::kForRead);
if (pBlkTblRcd.openStatus() != Acad::eOk)
return false;
AcDbBlockTableRecordIterator* pBTRIter = NULL;
Acad::ErrorStatus es = pBlkTblRcd->newIterator(pBTRIter);
if (Acad::eOk != es)
return false;
//绑定智能指针
std::unique_ptr<AcDbBlockTableRecordIterator> apBTRIter(pBTRIter);
for (apBTRIter->start(); !apBTRIter->done(); apBTRIter->step())
{
AcDbEntity* pTempEnt = NULL;
es = apBTRIter->getEntity(pTempEnt, AcDb::kForRead);
if (Acad::eOk != es)
continue;
arrid.append(pTempEnt->objectId());
pTempEnt->close();
}
return true;
}
2、得到块定义中的所有实体id(通过块定义id)
//************************************
// Summary: 得到块定义中的所有实体id(通过块定义id)
// Parameter:
// arrid - 输出块定义中所有实体id集合
// idBlkTblRcd - 输入块表记录id
// Return:
// Update Time: 2021-7-16 16:08:35 peihaodong
//************************************
bool PhdArxBlock::GetAllEntId(AcDbObjectIdArray& arrid, const AcDbObjectId& idBlkTblRcd) const
{
AcDbBlockTableRecordPointer pBlkTblRcd(idBlkTblRcd, AcDb::kForRead);
Acad::ErrorStatus es = pBlkTblRcd.openStatus();
if (es != Acad::eOk)
return false;
AcDbBlockTableRecordIterator* pBTRIter = NULL;
es = pBlkTblRcd->newIterator(pBTRIter);
if (Acad::eOk != es)
return false;
//绑定智能指针
std::unique_ptr<AcDbBlockTableRecordIterator> apBTRIter(pBTRIter);
for (apBTRIter->start(); !apBTRIter->done(); apBTRIter->step())
{
AcDbEntity* pTempEnt = NULL;
es = apBTRIter->getEntity(pTempEnt, AcDb::kForRead);
if (Acad::eOk != es)
continue;
arrid.append(pTempEnt->objectId());
pTempEnt->close();
}
return true;
}
3、得到块定义id(通过块名和数据库指针)
//************************************
// Summary: 得到块定义id(通过块名和数据库指针)
// Parameter:
// idBlkDef - 输出块定义id
// szBlkName - 输入块名
// pDb - 输入该块所在的数据库指针
// Return:
// Update Time: 2021-7-16 16:20:52 peihaodong
//************************************
bool PhdArxBlock::GetBlkDefId(AcDbObjectId& idBlkDef, LPCTSTR szBlkName, AcDbDatabase* pDb /*= acdbCurDwg()*/) const
{
AcDbBlockTableRecordPointer pBlkTblRec(szBlkName, pDb, AcDb::kForRead);
if (Acad::eOk != pBlkTblRec.openStatus())
return false;
idBlkDef = pBlkTblRec->objectId();
return true;
}
4、得到块定义id(通过块参照id)
bool PhdArxBlock::GetBlkDefId(AcDbObjectId& idBlkDef, const AcDbObjectId& idBlkRef) const
{
AcDbObjectPointer<AcDbBlockReference> pRef(idBlkRef, AcDb::kForRead);
if (Acad::eOk != pRef.openStatus())
return false;
idBlkDef = pRef->blockTableRecord();
return true;
}
5、得到块定义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;
}
6、得到所有的块定义名(得到数据库中所有的块名)
bool PhdArxBlock::GetAllBlkDefName(AcArray<CString>& arrBlkDefName, AcDbDatabase* pDb /*= acdbCurDwg()*/) const
{
AcDbBlockTablePointer pBlkTbl(pDb, AcDb::kForRead);
if (Acad::eOk != pBlkTbl.openStatus())
return false;
AcDbBlockTableIterator* pIt = NULL;
Acad::ErrorStatus es = pBlkTbl->newIterator(pIt);
if (Acad::eOk != es)
return false;
std::unique_ptr<AcDbBlockTableIterator> apIt(pIt);
for (apIt->start(); !apIt->done(); apIt->step())
{
AcDbBlockTableRecord* pBTRecord = NULL;
if (apIt->getRecord(pBTRecord, AcDb::kForRead) == Acad::eOk)
{
TCHAR* szName = NULL;
pBTRecord->getName(szName);
CString BlockName = szName;
if (_tcslen(szName) > 0)//过滤掉名称为空的块表;
{
if (BlockName.Find(_T("Model_Space")) == -1 && BlockName.Find(_T("Paper_Space")) == -1)
arrBlkDefName.append(BlockName);
}
acutDelString(szName);//必须清除动态字符串;
pBTRecord->close();
}
}
return true;
}
7、得到所有的块定义id(得到数据库中所有的块定义id)
bool PhdArxBlock::GetAllBlkDefId(AcDbObjectIdArray& arridBlkDef, AcDbDatabase* pDb /*= acdbCurDwg()*/) const
{
AcDbBlockTablePointer pBlkTbl(pDb, AcDb::kForRead);
if (Acad::eOk != pBlkTbl.openStatus())
return false;
AcDbBlockTableIterator* pIt = NULL;
Acad::ErrorStatus es = pBlkTbl->newIterator(pIt);
if (Acad::eOk != es)
return false;
std::unique_ptr<AcDbBlockTableIterator> apIt(pIt);
for (apIt->start(); !apIt->done(); apIt->step())
{
AcDbBlockTableRecord* pBTRecord = NULL;
if (apIt->getRecord(pBTRecord, AcDb::kForRead) == Acad::eOk)
{
TCHAR* szName = NULL;
pBTRecord->getName(szName);
CString BlockName = szName;
if (_tcslen(szName) > 0)//过滤掉名称为空的块表;
{
if (BlockName.Find(_T("Model_Space")) == -1 && BlockName.Find(_T("Paper_Space")) == -1)
arridBlkDef.append(pBTRecord->objectId());
}
acutDelString(szName);//必须清除动态字符串;
pBTRecord->close();
}
}
return true;
}
[/code] |
|