Hi All, I have had great support from these groups over the years, with many questions answered. I had some trouble finding a solution to exploding groups, so I thought I would post my code for comment and to help others (maybe). Ignore the error message utility. Dale
<code>
// Groups explode and purge uses a different logic
// iterate groups, iterate objects in group, remove objects, erase group
public static void ExplodeGroups()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// store drawing name for error report
string lstrDWGFileName = db.Filename.ToString();
// start a transaction
using(Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
DBDictionary NOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, false, false);
if(NOD.Contains("ACAD_GROUP"))
{
DBDictionary gd = tr.GetObject(NOD.GetAt("ACAD_GROUP"), OpenMode.ForWrite, false, false) as DBDictionary;
foreach(DictionaryEntry de in gd)
{
ObjectId Did = gd.GetAt(de.Key.ToString());
Group gp = (Group)tr.GetObject(Did, OpenMode.ForWrite, false, false);
// testing>>
// string gName = gp.Name;
// MessageBox.Show(gName);
// iterate entities and remove from group
ObjectIdCollection ids = new ObjectIdCollection(gp.GetAllEntityIds());
foreach(ObjectId oid in ids)
{
gp.Remove(oid);
}
// now delete/purge empty group
gp.Erase();
}
}
else
{
ed.WriteMessage("No Groups found");
}
}
catch(Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(UtilityLibrary.ErrorMessage(ex, MethodBase.GetCurrentMethod().Name.ToString(), lstrDWGFileName), "Something Happened...");
tr.Abort();
}
finally
{
// Save the new objects to the database
tr.Commit();
}
}
}
<code>
Hi,
Just on the quick glance, maybe you need to add functionality
to unlock / reset layers
Secondly, do not use tr.Abort(); inside the Using...End Using code block
just remove it from there,
Regards,
~'J'~
Hi, Thanks for feedback. I'll remove tr.abort as suggested. The layer reset as you commented is already taken care of in an earlier function. Regards, Dale
Correction:
Use:
ObjectId[] ids = gp.GetAllEntityIds();
instead of:
ObjectIdCollection ids = new ObjectIdCollection(gp.GetAllEntityIds());
Dale