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.


can i create a method ?

sjalifesjalife Member, Developers Posts: 24 PRO
edited October 2018 in Community Support
i need to create a method , because i need to do some operations into this method ...so, when i call this method, but how can i create a method and how can i call this method? 


  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    edited October 2018

    In FeatureScript, we usually say function instead of method (possibly because there are no objects, but mostly just a style choice).  Here is an example of the definition of a helper function in FS:

    function timesTwo(num is number) returns number
        var numTimesTwo = num * 2;
        return numTimesTwo;

    I may have missed the point of your question though?  Are you wondering how to create a feature (a.k.a. a button in the part studio that changes geometry)?  This tutorial may help:

    Happy to answer any more question you may have.
    Jake Rosenfeld - Modeling Team
  • Options
    sjalifesjalife Member, Developers Posts: 24 PRO
     yes, now i coulded create a function, but my function returns one string, and i wan to use this string, calling my function that is return a value (String), and according to the value that is returned i do some operation like if(String =="a") { do this} else if (String=="b"} do this.... etc.. how can i call this function inside precondition? for use the value returned and do my operations
  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646

    The precondition of a feature is used to define the UI it presents when a user clicks the button for the feature.  Arbitrary functions cannot be called in the precondition, as no FeatureScript is executed when deciding how the dialog should look.  The description of how the precondition becomes a feature dialog is described here:

    Many examples can be found in the standard library; a relatively simple one is the variable feature:
    Or the shell feature:

    If you share a link to a document with the feature you are working on, it may be easer to provide some guidance.
    Jake Rosenfeld - Modeling Team
Sign In or Register to comment.