码迷,mamicode.com
首页 > 其他好文 > 详细

objectARX 获取指定图层上所有实体ID

时间:2015-12-17 12:27:48      阅读:402      评论:0      收藏:0      [点我收藏+]

标签:

2015-12-17

 1 //获取指定图层上所有实体ID
 2 AcDbObjectIdArray GetAllEntityId(const TCHAR* layername)
 3 {
 4     AcDbObjectIdArray entIds;
 5     bool bFilterlayer = false;
 6     AcDbObjectId layerId;
 7     //获取指定图层对象ID
 8     if (layername != NULL)
 9     {
10         AcDbLayerTable *pLayerTbl = NULL;
11         acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl, AcDb::kForRead);
12         if (!pLayerTbl->has(layername))
13         {
14             pLayerTbl->close();
15             return entIds;
16         }
17         pLayerTbl->getAt(layername, layerId);
18         pLayerTbl->close();
19         bFilterlayer = true;
20     }
21     //获得块表
22     AcDbBlockTable *pBlkTbl = NULL;
23     acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlkTbl, AcDb::kForRead);
24     //块表记录
25     AcDbBlockTableRecord *pBlkTblRcd = NULL;
26     pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);
27     pBlkTbl->close();
28     //创建遍历器,依次访问模型空间中的每一个实体
29     AcDbBlockTableRecordIterator *it = NULL;
30     pBlkTblRcd->newIterator(it);
31     for (it->start(); !it->done(); it->step())
32     {
33         AcDbEntity *pEnt = NULL;
34         Acad::ErrorStatus es = it->getEntity(pEnt, AcDb::kForRead);
35         if (es == Acad::eOk)
36         {
37             if (bFilterlayer)//过滤图层
38             {
39                 if (pEnt->layerId() == layerId)
40                 {
41                     entIds.append(pEnt->objectId());
42                 }
43             }
44             else
45             {
46             //    entIds.append(pEnt->objectId());
47                 pEnt->close();
48             }
49         }
50     }
51     delete it;
52     pBlkTblRcd->close();
53     return entIds;
54 }

 

objectARX 获取指定图层上所有实体ID

标签:

原文地址:http://www.cnblogs.com/nightnine/p/5053375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!