- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
Am at a loss at the moment (again, as usual..)
Same DWG located on a network share
Using this method (update since first post) to explode within a selection
public static bool WithinSelection(SelectionSet selection) {
Document document = Application.DocumentManager.MdiActiveDocument;
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
editor.WriteMessage("\nAtiveViewPortId: " + editor.ActiveViewportId + ", CurrentViewportObjectId: " + editor.CurrentViewportObjectId);
var somthingExploded = false;
using (Transaction transaction = document.Database.TransactionManager.StartTransaction()) {
try {
BlockTable blockTable = transaction.GetObject(document.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId objectId in selection.GetObjectIds()) {
Entity selectedEntity = transaction.GetObject(objectId, OpenMode.ForRead) as Entity;
if (selectedEntity == null) {
editor.WriteMessage("\nNull entity with " + objectId.ToString());
continue;
}
if (selectedEntity is BlockReference selectedBlockReference) {
editor.WriteMessage("\nSelected handle:" + selectedEntity.Id.Handle + ", Name: " + selectedBlockReference.Name + ", BlockName:" + selectedBlockReference.BlockName);
using (DBObjectCollection resultOfExplode = new DBObjectCollection()) {
try {
selectedEntity.Explode(resultOfExplode);
foreach (DBObject obj in resultOfExplode) {
Entity explodedEntity = obj as Entity;
blockTableRecord.AppendEntity(explodedEntity);
transaction.AddNewlyCreatedDBObject(explodedEntity, true);
//editor.WriteMessage("\nAdding exploded into transaction " + explodedEntity.Id.Handle + " - " + explodedEntity);
}
if (resultOfExplode.Count > 0) {
editor.WriteMessage("\nExploded " + resultOfExplode.Count.ToString());
selectedEntity.UpgradeOpen();
selectedEntity.Erase(true);
somthingExploded = true;
} else {
editor.WriteMessage("\nNothing exploded");
}
} catch (Autodesk.AutoCAD.Runtime.Exception ex) {
editor.WriteMessage("\nError 1 " + ex.Message + " " + ex.StackTrace + "\nEntity: " + selectedEntity);
}
}
} else {
editor.WriteMessage("\nSelected handle is not a block:" + selectedEntity.Id.Handle + " - " + selectedEntity);
continue;
}
}
editor.WriteMessage("\nCommit transactoin");
transaction.Commit();
} catch (Autodesk.AutoCAD.Runtime.Exception ex) {
editor.WriteMessage("\nError 2 " + ex.Message + " " + ex.StackTrace);
transaction.Abort();
}
}
return somthingExploded;
}
Called like this two times in a row with the same coordinates
var selectionResult = editor.SelectCrossingWindow(new Point3d(x1, y1, 0), new Point3d(x2, y2, 0));
if (selectionResult.Status != PromptStatus.OK) {
editor.WriteMessage("\nInvalid selection - " + selectionResult.Status);
return;
}
var result = Explode.WithinSelection(selectionResult.Value);
Computer 1 yields this
AtiveViewPortId: (2569554406032), CurrentViewportObjectId: (0)
Selected handle:9695, Name: PICT_OWNER, BlockName:*Model_Space
Exploded 2
Commit transactoin
AtiveViewPortId: (2569554406032), CurrentViewportObjectId: (0)
Selected handle:9754, Name: BackingSheet, BlockName:*Model_Space
Exploded 325
Selected handle is not a block:974E - Autodesk.AutoCAD.DatabaseServices.Polyline2d
Commit transactoin
Computer 2
AtiveViewPortId: (1948773767824), CurrentViewportObjectId: (0)
Selected handle:9695, Name: PICT_OWNER, BlockName:*Model_Space
Exploded 2
Commit transactoin
True
Invalid selection - Error
What steps can I take to try and figure out why the second explode fails on computer 2? Can I get more details as to why the selection is an Error? My best clue so far is that if I call a different CommandMethod, that will execute the same WithinSelection-method, it works but the handles on selected and exploded entities are not the same as Computer 1..
Selected handle:97CA - Autodesk.AutoCAD.DatabaseServices.BlockReference
Exploded into 325
Selected handle:97C4 - Autodesk.AutoCAD.DatabaseServices.Polyline2d
Selected is not BlockReference, skipping
Commit transactoin
Solved! Go to Solution.