Ask user to select objects
Updated : 02 December 2024
TopSolid Automation provides access to a dedicated interface, IUser
.
This interface includes various methods to prompt the user for selections, as well as retrieve the current selection (whether an entity or an operation).
ach picking method within this interface takes a UserQuestion
as a parameter and returns a UserAnswerType
(../api/kernel/TopSolid.Kernel.Automating.UserAnswerType.html)
User Questions
Below is a comprehensive list of possible interactions:
Basic selection:
UserQuestion myUserQuestion = new UserQuestion();
Selection with title, prompt, label:
UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt");
Selection allowing previous:
UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsPrevious);
Selection allowing next:
UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsNext);
Selection allowing empty:
UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsEmpty);
Selection allowing creation:
UserQuestion myUserQuestion = new UserQuestion("My Point Selection", "Selected Point", "Select a Point", UserQuestionFlags.AllowsCreation);
Note
This last type of selection is only available for entities that can be created via the UI, such as points, for example.
User Answer Type
The UserAnswerType
represents the response to a user question.
It can take one of the following three values:
- OK
- Cancel
- Previous
Complete example
The user responses can be incorporated into the UI interaction logic, as demonstrated in the following example:
try
{
TopSolidHost.Application.StartModification("increase parameter value", false);
TopSolidHost.Documents.EnsureIsDirty(ref currentDoc);
UserQuestion myUserQuestion = new UserQuestion();
myUserQuestion = new UserQuestion("My Point Selection", "Selected Point", "Select a Point", UserQuestionFlags.AllowsCreation);
SmartPoint3D smpt = null;
again:
TopSolidHost.User.AskPoint3D(myUserQuestion, smpt, out smpt);
myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsPrevious);
UserAnswerType userAnswer = TopSolidHost.User.AskShape(myUserQuestion, ElementId.Empty, out ElementId outElementId);
if (userAnswer == UserAnswerType.Previous)
{
goto again;
}
TopSolidHost.Application.EndModification(true, true);
}
catch (Exception ee)
{
TopSolidHost.Application.EndModification(false, false);
}