天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 5|回复: 0

getObjects获取块的函数

[复制链接]
  • TA的每日心情
    开心
    昨天 15:23
  • 签到天数: 69 天

    [LV.6]常住居民II

    410

    主题

    167

    回帖

    2704

    积分

    管理员

    积分
    2704
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    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;
    }

     

     

     

     

    getObjects获取块的函数
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|

    GMT+8, 2024-7-1 05:30 , Processed in 0.059057 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表