//根据输入的对象,找到这个对象属于的组名 private string GetentgroupName(Entity ent) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = HostApplicationServices.WorkingDatabase; string groupName = ""; using (Transaction trans = db.TransactionManager.StartTransaction()) { //打开当前数据库的组字典对象 DBDictionary dict = (DBDictionary)trans.GetObject(db.GroupDictionaryId, OpenMode.ForRead);
foreach (var gptemp in dict) { ObjectId gpid = dict.GetAt(gptemp.Key); //由于要在组中进行去除对象的操作,因此以写的方式打开找到的组对象 Group gp = (Group)trans.GetObject(gpid, OpenMode.ForWrite); bool isHas = gp.Has(ent); if (isHas == true)//如果在这个组中,则返回这个祖名 { groupName = gptemp.Key; break; }
} trans.Commit(); } return groupName; } |