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 you use "conditionals" with variables?

brian_bradybrian_brady Member, Developers Posts: 367 EDU
What I mean here is can you do things like; if x>10 then y=0.5*x else y=x. What about logical functions like AND and OR? If conditionals and logicals could be used, then I could easily "program" multiple variables to change off one or two primary parameters. For example, enter a woodruff key number (i.e. 204) into a variable and use conditional logic to set all of the dimensions. Diameter and thickness can be done without conditionals, but the offset cannot, it varies from size to size.

On the other hand, can FS be used to just import existing variables and set values to new variables that can be used in a part model without actually making any geometry?

Best Answer

Answers

  • brian_bradybrian_brady Member, Developers Posts: 367 EDU
    Great. Thanks for the answer. Can AND and OR be used, maybe as && and ||?
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 910
    Yes -- exactly && and ||.
    Ilya Baran \ Director of FeatureScript \ Onshape Inc
  • jonathan_monettejonathan_monette Member Posts: 17 PRO
    Is there a list of these logical variable control that I could refer to? Or documentation's?
  • MBartlett21MBartlett21 Member Posts: 1,501 EDU
    @jonathan_monette
    These are just standard javascript constructs
    MB - I make FeatureScripts: view FS (My FS's have "Official" beside them)
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 910
    These are not JavaScript but FeatureScript -- there's some syntax similarity, but it's unrelated otherwise.  Documentation "for mechanical engineers" is here: https://cad.onshape.com/help/Content/numeric-fields.htm?Highlight=expressions but is incomplete.  A more complete description is in the FeatureScript documentation: https://cad.onshape.com/FsDoc/syntax.html#expression-types

    Note that what you enter into the expression fields is not quite FeatureScript syntax.  The main differences are that shorthand units (eg., "in" rather than "inch") are allowed, the multiplication before a unit is optional in some cases (as in "3 inch" rather than "3 * inch"), #foo for accessing context variable foo, and a couple of other minor differences.
    Ilya Baran \ Director of FeatureScript \ Onshape Inc
Sign In or Register to comment.