using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
TypedValue[] acTypValAr5 = new TypedValue[1];
acTypValAr5.SetValue(new TypedValue((int)DxfCode.BlockName, "1"), 0);
SelectionFilter acSelFtr5 = new SelectionFilter(acTypValAr5);
PromptSelectionResult acSSPrompt5 = acEd.SelectAll(acSelFtr5);
if (acSSPrompt5.Status == PromptStatus.OK)
{
//acDoc.SendStringToExecute("explode ", true, false, true);
SelectionSet acSSet5 = acSSPrompt5.Value;
DBObjectCollection objs = new DBObjectCollection();
foreach (ObjectId acSSetObject5 in acSSet5.GetObjectIds())
{
//Entity ent5 = acTrans.GetObject(acSSetObject5.ObjectId, OpenMode.ForWrite) as Entity;
Entity ent5 = acSSetObject5.GetObject(OpenMode.ForWrite) as Entity;
if (ent5 is BlockReference)
{
BlockReference blkRef = (BlockReference)acTrans.GetObject(acSSetObject5, OpenMode.ForWrite);
BlockTableRecord btr2 = (BlockTableRecord)acTrans.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite);
blkRef.Explode(objs);
}
}
}
acTrans.Commit();
}
炸开块后,需要将实体重新添加到模型空间,否则ent.Explode(objs)就没有起作用;
//
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = trans.GetObject(objectId, OpenMode.ForWrite) as Entity;
DBObjectCollection objs = new DBObjectCollection();
ent.Explode(objs);
foreach (DBObject obj in objs)
{
if (obj is Entity)
{
db.AddToModelSpace((Entity)obj);
}
}
if (IsDelateBlock)
{
objectId.Erase();
}
trans.Commit();
}