Set a Default Answer to Editor.GetString()

Set a Default Answer to Editor.GetString()

Anonymous
Not applicable
1,469 Views
3 Replies
Message 1 of 4

Set a Default Answer to Editor.GetString()

Anonymous
Not applicable

The editor class has a method called GetString which prompts the user for a string value via AutoCAD's command prompt. I call it in this wrapper method:

 

public static string PromptUserForString(string message = "Enter a string: ", string defaultAnswer = "")
{
    return _editor.GetString("\n" + message).StringResult;
}

 

The argument message becomes the message the user sees when prompted for a string. How do I set it up so that the value of default answer is automatically set to be the answer so that if the user hits enter right away that becomes the value like in the screen shot below

 

Capture.PNG

 

So 1 is automatically typed as an answer meaning the user can either hit enter for the value of 1 or change 1 to whatever non-default answer they want

0 Likes
Accepted solutions (1)
1,470 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

Editor.GetString() has an overload that takes PromptStringOptions as input parameter, so that you can define your PromptStringOptions to gain more controls on how Editor.GetString() works.

 

In your case, you can look at PromptStringOptions.DefaultValue and/or PromptStringOptions.Keywords.

 

HTH

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

zrobert
Advocate
Advocate
Accepted solution

Something like this...

 

var pso = new PromptStringOptions("\nEnter a string:");
pso.DefaultValue = "default";
var psr = editor.GetString(pso);

if (psr.Status == PromptStatus.OK)
    {
        // do job ...
    }

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Exactly what I needed, thanks!

0 Likes