Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was trying to add exploding AEC objects as a step in a larger command.
So in my command class I simply have this
[CommandMethod(nameof(CleanupTest))]
public void CleanupTest()
{
Cleanup.CleanupTool.Cleanup();
}
Then in the Cleanup method
public static class CleanupTool
{
private static Database _db = null;
private static Editor _ed = null;
private static List<ObjectId> _allEntities = new List<ObjectId>();
public static void Cleanup()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
_db = doc.Database;
_ed = doc.Editor;
_allEntities.Clear();
_db.UnlockTurnOnThawAllLayers();
GetAllEntities(_ed);
if (!_allEntities.Any()) return;
ExplodeAEC();
bool moreBlocks = true;
while (moreBlocks)
{
moreBlocks = ExplodeBlocks();
}
///the rest of my code
}
}
I get a selection so I know what entities the user wants to operate with, and then I try to explode the AEC objects which requires sending the EXPLODE command instead of exploding using the API
private static void GetAllEntities(Editor ed)
{
var totalSelection = ed.GetSelection(new PromptSelectionOptions
{
MessageForAdding = $"\nSelect the FLOOR plan to clean:"
});
if (totalSelection.Status != PromptStatus.OK) return;
_allEntities = totalSelection.Value.GetObjectIds().ToList();
}
private static void ExplodeAEC()
{
var aec = _allEntities
.Where(id => id.ObjectClass.DxfName.Contains("AEC"))
.ToList();
if (!aec.Any()) return;
_ed.SetImpliedSelection(aec.ToArray());
//_ed.Document.SendStringToExecute("._EXPLODE", true, false, false);
_ed.Command("._EXPLODE", "P");
}
Neither using Editor.Command() or Document.SendStringToExecute() work in this context. The terminal says this
Select the FLOOR plan to clean:
._EXPLODE
Select object: P
*Invalid selection*
Expects a point or Last/ALL/Group
But If I instead extract the AEC portion into its own command then it works
[CommandMethod(nameof(CleanAEC))]
public void CleanAEC()
{
var _ed = Active.Editor;
var selection = _ed.GetSelection();
if (selection.Status != PromptStatus.OK) return;
var aec = selection.Value.GetObjectIds()
.Where(id => id.ObjectClass.DxfName.Contains("AEC"))
.ToList();
if (!aec.Any()) return;
_ed.SetImpliedSelection(aec.ToArray());
_ed.Document.SendStringToExecute("._EXPLODE P", true, false, false);
}
I have tried commenting out the rest of the Cleanup method code to see if something that happens after ExploeAEC is causing the problem. Unfortunately it did not seem to help.
Solved! Go to Solution.