Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

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

joshtargojoshtargo Member Posts: 230 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

  • GregBrownGregBrown Member, Onshape Employees, csevp Posts: 194
    edited October 14 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

  • GregBrownGregBrown Member, Onshape Employees, csevp Posts: 194
    edited October 14 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!

  • joshtargojoshtargo Member Posts: 230 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

Sign In or Register to comment.