How do I add buttons to a UI window like the ones in Routing Curve?

joshtargo
joshtargo Member Posts: 695 EDU

How do I add buttons to a UI window like the ones in Routing Curve?

I tried to look at the code, but it links to something that I cant seem to access.

Best Answer

  • GregBrown
    GregBrown Member, Onshape Employees, csevp, pcbaevp Posts: 412 image
    edited October 2024 Answer ✓

    I'll send you one example, and clean it up to share for the rest of the forum… But for now:

    In the predicate for the feature you can create a button type like:

        annotation { "Name" : "My Button" }
        isButton(definition.doSomething);
    

    Also you need to include a new parameter in your editing logic function, so the function definition looks something like this:

    export function myEditLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map, hiddenQueries is Query, clickedButton is string) returns map
    {
    
    //do stuff
    // …
    
        if (clickedButton == "doSomething")
        {
            definition.count = oldDefinition.count + 1;
            return anotherFunctionPerhaps(context, id, definition);
        }
    
    //…
    
    return definition;
    
    }
    

    When you "do stuff" you'll need to check for clickedButton (remember it will be a string) then… do something!

Answers

  • GregBrown
    GregBrown Member, Onshape Employees, csevp, pcbaevp Posts: 412 image
    edited October 2024 Answer ✓

    I'll send you one example, and clean it up to share for the rest of the forum… But for now:

    In the predicate for the feature you can create a button type like:

        annotation { "Name" : "My Button" }
        isButton(definition.doSomething);
    

    Also you need to include a new parameter in your editing logic function, so the function definition looks something like this:

    export function myEditLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map, hiddenQueries is Query, clickedButton is string) returns map
    {
    
    //do stuff
    // …
    
        if (clickedButton == "doSomething")
        {
            definition.count = oldDefinition.count + 1;
            return anotherFunctionPerhaps(context, id, definition);
        }
    
    //…
    
    return definition;
    
    }
    

    When you "do stuff" you'll need to check for clickedButton (remember it will be a string) then… do something!

  • joshtargo
    joshtargo Member Posts: 695 EDU

    Thank you, this can be a solution for a few different UI needs...

    Now if only my real work would slow down enough for me to just sit and code for a while

  • christopher_dziuba
    christopher_dziuba Member Posts: 124 ✭✭✭

    YEEEHAAAW thanks for this legend!