Search code examples
c#.netautocad

How to have a custom prompt message when using GetSelection in .net c# autocad?


I simply would like to display a custom message when asking a user to select objects, using a GetSelection with a SelectionFilter.

For now I am just writing to the editor then prompting the GetSelection with a filter e.g. on MTEXT

TypedValue[] typedValues1 = { new TypedValue(0, "MTEXT") };
SelectionFilter selectionFilter1 = new SelectionFilter(typedValues1);
ed.WriteMessage("Select MTEXT:");
PromptSelectionResult selMtext = ed.GetSelection(selectionFilter1);
if (selMtext.Status == PromptStatus.OK && selMtext.Value.Count == 1)
{...}

When running the command in Autocad I get as expected: Select MTEXT: Select objects:

Then repeating 'Select Objects: for each selection until press Enter)

But I just want to have only my custom text "Select MTEXT:" to be displayed. A workaround is be to use a GetEntity,which can have a custom message, then Check and filter only objects with the right class (ObjectClass.DxfName)? But it means that all objects selected are stored in the selection, not only the targeted one like 'MTEXT'. Please help, thank you


Solution

  • You should use PromptSelectionOptions.MessageForAdding.

    TypedValue[] typedValues1 = { new TypedValue(0, "MTEXT") };
    SelectionFilter selectionFilter1 = new SelectionFilter(typedValues1);
    var options = new PromptSelectionOptions();
    options.MessageForAdding = "\nSelect MTEXT: ";
    PromptSelectionResult selMtext = ed.GetSelection(options, selectionFilter1);
    if (selMtext.Status == PromptStatus.OK && selMtext.Value.Count == 1)
    { ... }