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

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

Anonymous
Not applicable
707 Views
1 Reply
Message 1 of 2

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

Anonymous
Not applicable

I'm trying to write a method that prompts the user to pick a group and returns the ObjectId of the group so I can use it later. Right now that method looks like 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) as Group;
                        if (groupToCheck != null)
                        {
                            return groupToCheck.Id;
                        }
                    }
                }
                else
                {
                    throw new IOException();
                }
                return ObjectId.Null;
            }
        }

 

When I call the method it prompts the user like I want it to. However, when I pick the group it always returns ObjectId.Null meaning it isn't realizing I'm picking a group. I don't know what's wrong or how to fix it. 

0 Likes
Accepted solutions (1)
708 Views
1 Reply
Reply (1)
Message 2 of 2

SENL1362
Advisor
Advisor
Accepted solution
Groups can be found through the GetPersistentReactorIds of the entities selected.

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

0 Likes