c# - Method that prompts user to pick a group and gets that group's ID -


i'm trying write method prompts user pick group , returns objectid of group can use later. right method looks this:

public static objectid promptuserforgroup()         {             using (transaction tr = _database.transactionmanager.starttransaction())             using (documentlock doclock = _activedocument.lockdocument())             {                  promptselectionresult activeselectionprompt = _editor.getselection();                 if (activeselectionprompt.status == promptstatus.ok)                 {                     objectid[] ids = activeselectionprompt.value.getobjectids();                     foreach (objectid id in ids)                     {                         group grouptocheck = tr.getobject(id, openmode.forwrite) group;                         if (grouptocheck != null)                         {                             return grouptocheck.id;                         }                     }                 }                 else                 {                     throw new ioexception();                 }                 return objectid.null;             }         } 

when call method prompts user want to. however, when pick group returns objectid.null meaning isn't realizing i'm picking group. don't know what's wrong or how fix it.

actually group not derived entity, therefore not on modelspace (blocktablerecord). result, there no group on drawing, on dictionary.

when user select something, need find group belongs. here sample code:

[commandmethod("findgroup")] static public void findgroup() {   document doc =       application.documentmanager.mdiactivedocument;   database db = doc.database;   editor ed = doc.editor;   promptentityresult acssprompt =       ed.getentity("select entity find group");    if (acssprompt.status != promptstatus.ok)     return;    using (transaction tx =       db.transactionmanager.starttransaction())   {     entity ent = tx.getobject(acssprompt.objectid,                             openmode.forread) entity;     objectidcollection ids = ent.getpersistentreactorids();      bool bpartofgroup = false;     foreach (objectid id in ids)     {       dbobject obj = tx.getobject(id, openmode.forread);        if (obj group)       {         group group = obj group;         bpartofgroup = true;         ed.writemessage(             "entity part of " + group.name + " group\n");        }     }      if (!bpartofgroup)       ed.writemessage(               "entity not part of group\n");     tx.commit();   } } 

source: http://adndevblog.typepad.com/autocad/2012/04/how-to-detect-whether-entity-is-belong-to-any-group-or-not.html


Comments