/// <summary>
/// Creates a group with the name as prefix followed by a number
/// </summary>
/// <param name="ents"></param>
/// <param name="prefix"></param>
public static void CreateAnonymousGroup(ObjectIdCollection groupEntIDs, string prefix)
{
if (!groupEntIDs.Contains(ObjectId.Null))
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary groupDictionary = (DBDictionary)tr.GetObject(db.GroupDictionaryId, OpenMode.ForWrite, true);
int number = groupDictionary.Count;
string groupName = prefix + number;
if (IsValidSymbolName(groupName))
{
while (groupDictionary.Contains(groupName))// Don't allow duplicate groupName
{
number++;
groupName = prefix + number;
}
// presumably we can add it now.
Group grp
= new Group(groupName,
true); groupDictionary.SetAt(groupName, grp);
tr.AddNewlyCreatedDBObject(grp, true);
grp.InsertAt(0, groupEntIDs);
}
tr.Commit();
}
}
}