Exploding AEC objects after setting implied selection is behaving inconsistently

Exploding AEC objects after setting implied selection is behaving inconsistently

nshupeFMPE3
Advocate Advocate
486 Views
3 Replies
Message 1 of 4

Exploding AEC objects after setting implied selection is behaving inconsistently

nshupeFMPE3
Advocate
Advocate

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.

0 Likes
Accepted solutions (2)
487 Views
3 Replies
Replies (3)
Message 2 of 4

ActivistInvestor
Mentor
Mentor
Accepted solution

Try it like this:

 

private static void ExplodeAEC()
{
   var aec = _allEntities
         .Where(id => id.ObjectClass.DxfName.Contains("AEC"))
         .ToArray();

   if(!aec.Any()) return;

   var ss = SelectionSet.FromObjectIds(aec);
   ed.InitCommandVersion(2);
   ed.Command("._EXPLODE", ss, "");
}
0 Likes
Message 3 of 4

nshupeFMPE3
Advocate
Advocate

Of course that worked. As always thank you very much. Is there any documentation regarding Editor.InitCommandVersion()? I like to learn more about these obscure "tools" so I might be ready next time.

0 Likes
Message 4 of 4

ActivistInvestor
Mentor
Mentor
Accepted solution

InitCommandVersion() tells the next command to be issued to use the same prompting sequence in scripted commands that it uses when the command is used interactively by the user.

 

A command will always use the legacy prompting sequence (if there is one) when it is being scripted, to avoid breaking script compatibility. InitCommandVersion() allows you to override that, to have a command use the same prompting sequence in scripted input that's used when the command is used interactively.

 

The EXPLODE command originally accepted only a single entity. At some point, it was changed to allow multiple objects to be selected, which involves a different prompting sequence. So in this case, InitCommandVersion() is telling EXPLODE to allow multiple objects to be supplied when it is being scripted, which it would otherwise not do.