当前位置: 代码迷 >> 综合 >> C#ObjectArx Cad获取模型空间得所有实体
  详细解决方案

C#ObjectArx Cad获取模型空间得所有实体

热度:4   发布时间:2023-12-17 03:57:31.0
        /// <summary>/// 实体ID的列表/// </summary>/// <returns></returns>public static List<ObjectId> GetEntitiesInModelSpace(){List<ObjectId> objects = new List<ObjectId>();using (Transaction transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()){BlockTable blockTable = (BlockTable)transaction.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);foreach (ObjectId objId in blockTableRecord){objects.Add(objId);}transaction.Commit();}return objects;}/// <summary>/// 实体ID的列表(某个图层)/// </summary>/// <returns></returns>public static List<ObjectId> GetEntitiesInModelSpace(string layerName){List<ObjectId> objects = new List<ObjectId>();using (Transaction transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()){BlockTable blockTable = (BlockTable)transaction.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);//遍历所有得记录表记录foreach (ObjectId objId in blockTableRecord){//获取实体Entity entity = (Entity)transaction.GetObject(objId, OpenMode.ForRead);//判断实体得所属图层if (entity.Layer == layerName){objects.Add(objId);}}transaction.Commit();}return objects;}