[求助] 选择一个组实体,获得组名
<p>如题。。。求助</p> 看本版的精华帖 <div> //根据输入的对象,找到这个对象属于的组名</div><div> private string GetentgroupName(Entity ent)</div><div> {</div><div> Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;</div><div> Database db = HostApplicationServices.WorkingDatabase;</div><div> string groupName = "";</div><div> using (Transaction trans = db.TransactionManager.StartTransaction())</div><div> {</div><div> //打开当前数据库的组字典对象</div><div> DBDictionary dict = (DBDictionary)trans.GetObject(db.GroupDictionaryId, OpenMode.ForRead);</div><div><br/></div><div> foreach (var gptemp in dict)</div><div> {</div><div> ObjectId gpid = dict.GetAt(gptemp.Key);</div><div> //由于要在组中进行去除对象的操作,因此以写的方式打开找到的组对象</div><div> Group gp = (Group)trans.GetObject(gpid, OpenMode.ForWrite);</div><div> bool isHas = gp.Has(ent);</div><div> if (isHas == true)//如果在这个组中,则返回这个祖名</div><div> {</div><div> groupName = gptemp.Key;</div><div> break;</div><div> }</div><div><br/></div><div> }</div><div> trans.Commit();</div><div> }</div><div> return groupName;</div><div> }</div> 非常感谢两位的回答,我已经找到问题所在:版本问题。CAD2006版本没有var和DictionaryEntry,痛苦找了好久。用CAD2008测试了后都好使。。。
页:
[1]