.NET

.NET

Reply
Valued Contributor
swaywood
Posts: 91
Registered: ‎08-22-2013
Message 1 of 3 (135 Views)
Accepted Solution

How to select all groups whitch the groupname contains 'PART-*'

135 Views, 2 Replies
06-25-2014 08:10 PM

Hi all:

in a drawing there are many groups.

the group name just like 'PART-1','PART-2','PART-…'

can i use a filter to select all the groups at ont time?

I am new, could you kindly give me some code to learn how to do that?

best regards

swaywood

Hi,

 

You can't use a selection filter, but you can get the ObjectIdS of the entities within the groups which names match a specified pattern.

 

SelectByGroupName(db, "PART-*");

 

 private ObjectIdCollection SelectByGroupName(Database db, string pattern)
{
ObjectIdCollection result = new ObjectIdCollection();
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
DBDictionary NOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
DBDictionary groups = (DBDictionary)tr.GetObject(NOD.GetAt("ACAD_GROUP"), OpenMode.ForRead);
foreach (DBDictionaryEntry entry in groups)
{
if (Utils.WcMatchEx(entry.Key, pattern, true))
{
Group group = (Group)tr.GetObject(entry.Value, OpenMode.ForRead);
foreach (ObjectId id in group.GetAllEntityIds())
{
result.Add(id);
}
}
}
tr.Commit();
}
return result;
}

 

*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 2 of 3 (118 Views)

Re : How to select all groups whitch the groupname contains 'PART-*'

06-25-2014 11:55 PM in reply to: swaywood

Hi,

 

You can't use a selection filter, but you can get the ObjectIdS of the entities within the groups which names match a specified pattern.

 

SelectByGroupName(db, "PART-*");

 

        private ObjectIdCollection SelectByGroupName(Database db, string pattern)
        {
            ObjectIdCollection result = new ObjectIdCollection();
            using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                DBDictionary NOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                DBDictionary groups = (DBDictionary)tr.GetObject(NOD.GetAt("ACAD_GROUP"), OpenMode.ForRead);
                foreach (DBDictionaryEntry entry in groups)
                {
                    if (Utils.WcMatchEx(entry.Key, pattern, true))
                    {
                        Group group = (Group)tr.GetObject(entry.Value, OpenMode.ForRead);
                        foreach (ObjectId id in group.GetAllEntityIds())
                        {
                            result.Add(id);
                        }
                    }
                }
                tr.Commit();
            }
            return result;
        }

 

Gilles Chanteau
Valued Contributor
swaywood
Posts: 91
Registered: ‎08-22-2013
Message 3 of 3 (94 Views)

Re: How to select all groups whitch the groupname contains 'PART-*'

06-26-2014 05:39 PM in reply to: swaywood
hi,gile:
thank you so much!
I'll try it.
best regards.
swaywood
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.