Search Results for

    Show / Hide Table of Contents

    alt-text 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();
      
      

      alt-text

    • Selection with title, prompt, label:

      
      UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt");
      
      

      alt-text

    • Selection allowing previous:

      
      UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsPrevious);
      
      

      alt-text

    • Selection allowing next:

      
      UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsNext);
      
      

      alt-text

    • Selection allowing empty:

      
      UserQuestion myUserQuestion = new UserQuestion("My Title", "My Label", "My Prompt", UserQuestionFlags.AllowsEmpty);
      
      

      alt-text

    • Selection allowing creation:

      
      UserQuestion myUserQuestion = new UserQuestion("My Point Selection", "Selected Point", "Select a Point", UserQuestionFlags.AllowsCreation);
      
      

      alt-text


    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);
    }
    
    In This Article
    • User Questions
    • User Answer Type
    • Complete example
    • Term of use
    • Corporate information
    • Privacy Policy - GDPR

    Copyright ©2024 TopSolid - All rights reserved.