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.

Options

Help with conditional dimensions syntax

brian_jordanbrian_jordan Member, Developers Posts: 139 ✭✭✭

In searching the help files I have found  the following

You can also use ternary operators (such as '?') which can yield conditional results. For example, say the length of a sketch entity should be 7 inches if the width is greater than 5 inches. It can be written this way:

#width>5?7:4

How can I incorporate this into an If... Else statement so that in one hit I can specify in addition eg #width>8?9.2:4 #width>10?12.4:4 I'm sure this is possible but for the moment the syntax escapes me.

Thank you

Comments

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,391
    You're almost there - the biggest thing you are missing is units, plus you must test the larger value first otherwise the second "if" would never be reached. Parentheses around the embedded "if" are also required.

    #width > 10 in ? 12.4 in : (#width > 8 in ? 9.2 in : 4 in)
    Senior Director, Technical Services, EMEAI
  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    edited April 2018
    @brian_jordan

    You can nest additional ternaries anywhere you want in the expression.  I like to do something certain in the 'if' and then do more logic in the 'else' so I would phrase this like:

    #width>10?12.4:(#width>8?9.2:4)

    but some other ways would be:
    #width>8?(#width>10?12.4:9.2):4
    #width<8?4:(#width<10?9.2:12.4)

    All work out to the same logic in the end :)

    Jake Rosenfeld - Modeling Team
  • Options
    brian_jordanbrian_jordan Member, Developers Posts: 139 ✭✭✭
    @NeilCooke @Jake_Rosenfeld Thank you both for your help. So near and yet so far!
Sign In or Register to comment.