TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 昨天 15:23 |
---|
签到天数: 69 天 [LV.6]常住居民II
管理员
- 积分
- 2704
|
bool getObjects( ACHAR *xRefName, ACHAR *layer, std::vector<AcDbEntity*> *objects, AcGeMatrix3d *transform )
{
Acad::ErrorStatus errorStatus;
AcDbDatabase *database = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *blockTable = NULL;
AcDbBlockTableRecord *modelBlockTableRecord = NULL;
AcDbBlockTableRecord *blockTableRecord = NULL;
AcDbDatabase *xRefDatabase = NULL;
const ACHAR *xRefPath = NULL;
AcDbDatabase *xRefDWGDatabase = NULL;
AcDbBlockTable *xRefBlockTable = NULL;
AcDbBlockTableRecord *xRefBlockTableRecord = NULL;
//Get the block table for our database
errorStatus = database->getBlockTable(blockTable, AcDb::kForRead);
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError getting block table %s", acadErrorStatusText( errorStatus ) );
return false;
}
//Get the table record in model space
errorStatus = blockTable->getAt(ACDB_MODEL_SPACE,modelBlockTableRecord,AcDb::kForRead);
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError getting model space block table record %s", acadErrorStatusText( errorStatus ) );
blockTable->close();
return false;
}
//Get the block table record for the external reference
errorStatus = blockTable->getAt( xRefName, blockTableRecord, AcDb::kForRead );
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError could not get xref %s %s", xRefName, acadErrorStatusText( errorStatus ) );
modelBlockTableRecord->close();
blockTable->close();
return false;
}
xRefDatabase = blockTableRecord->xrefDatabase(true);
if( xRefDatabase == NULL )
{
acutPrintf(L"\nCould not get external reference database" );
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
return false;
}
//Get path for external reference dwg file
xRefPath = acdbOriginalXrefFullPathFor( xRefDatabase );
if( xRefDatabase == NULL )
{
acutPrintf(L"\nCould not get external reference path" );
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
return false;
}
//Get database for the external reference drawing
xRefDWGDatabase = new AcDbDatabase(Adesk::kFalse);
errorStatus = xRefDWGDatabase->readDwgFile(xRefPath);
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError could not read xref file %s", acadErrorStatusText( errorStatus ));
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
return false;
}
//Get the block table for the open model reference file
errorStatus = xRefDWGDatabase->getBlockTable( xRefBlockTable, AcDb::kForRead );
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError could not load xref block table %s", acadErrorStatusText( errorStatus ));
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
return false;
}
//Get the definition for the block in the the external reference
errorStatus = xRefBlockTable->getAt( L"TRINA 335W MODULE", xRefBlockTableRecord, AcDb::kForRead );
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError could not get xref block table record %s", acadErrorStatusText( errorStatus ));
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
xRefBlockTable->close();
return false;
}
AcDbObjectIdArray blockIds;
errorStatus = xRefBlockTableRecord->getBlockReferenceIds( blockIds );
if( errorStatus != Acad::eOk )
{
acutPrintf(L"\nError could not get xref block ids %s", acadErrorStatusText( errorStatus ));
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
xRefBlockTable->close();
xRefBlockTableRecord->close();
return false;
}
for( int i = 0; i < blockIds.length(); i++ )
{
AcDbEntity *ent = NULL;
acdbOpenObject( ent, blockIds.at(i), AcDb::kForRead );
if( ent != NULL )
{
objects->push_back( ent );
}
}
modelBlockTableRecord->close();
blockTable->close();
blockTableRecord->close();
xRefBlockTable->close();
xRefBlockTableRecord->close();
return true; |
|