Message 1 of 2
Entity.Explode() method does not output circles to DBObject
Not applicable
06-22-2021
11:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all - I'm creating a command which creates a new document, copies a block to it, and then explodes that block into machine-readable geometric entities that can be saved as a .dxf and sent to the machine in our shop. Right now the code is mostly functional, however when the "explode" method is called the resulting entities do not include any circles that were part of the original block. At first I thought this was an issue resulting from block anonymity, as many of these circles were copied from standard-sized bore circles, however even non-anonymized circles I added to the block as a test also get dropped. I've included part of my code below:
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockReference bR = trans.GetObject(id, OpenMode.ForRead) as BlockReference;
BlockTableRecord bTR = trans.GetObject(bR.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
if (bTR.Comments.Contains("_MR_"))
{
ObjectIdCollection idCollection = new ObjectIdCollection();
idCollection.Add(id);
Document newDoc = Application.DocumentManager.Add("acad.dwt");
Database destDB = newDoc.Database;
Application.DocumentManager.MdiActiveDocument = newDoc;
using (DocumentLock docLock = newDoc.LockDocument())
{
using (Transaction trans0 = destDB.TransactionManager.StartTransaction())
{
trans0.TransactionManager.QueueForGraphicsFlush();
IdMapping iMap = new IdMapping();
db.WblockCloneObjects(idCollection, destDB.CurrentSpaceId, iMap, DuplicateRecordCloning.Ignore, false);
PromptSelectionResult pSR = newDoc.Editor.SelectAll();
foreach(ObjectId id0 in pSR.Value.GetObjectIds())
{
BlockTable destBT = trans0.GetObject(destDB.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord destBTR = trans0.GetObject(destBT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
DBObjectCollection dBObjectCollection = new DBObjectCollection();
Entity entity = trans0.GetObject(id0, OpenMode.ForWrite) as Entity;
entity.Explode(dBObjectCollection);
entity.Erase();
foreach(Entity ent in dBObjectCollection)
{
destBTR.AppendEntity(ent);
trans0.AddNewlyCreatedDBObject(ent, true);
}
}
Application.DocumentManager.MdiActiveDocument = doc;
trans0.Commit();
destDB.DxfOut(rootPath + @"\" + pDirectory.StringResult + "_" + i.ToString() + ".dxf", 16, DwgVersion.AC1009);