How to define a range dependent variable?

adi_noyboer004
adi_noyboer004 Member Posts: 3 PRO

Hello to you all,
I'm trying to define a variable (z) by a range of values for variable (k)
'k' range 'z' value

6<z=<8 1

8<z=<10 2

10<z 3


I was trying to define a variable by nesting expression { ((#k>6&&#k=<8)?1:(#k>8&&#k=<10)?2:3) }, but to no avail.
Please advise.

Sincerly

Answers

  • _anton
    _anton Member, Onshape Employees Posts: 553 image

    <=, not =<

  • adi_noyboer004
    adi_noyboer004 Member Posts: 3 PRO

    I tried it as well, same resaults

  • eric_pesty
    eric_pesty Member, pcbaevp Posts: 2,905 PRO

    It gets a bit confused about the second part of the ternary, this should work if you add these brackets:

    (#k>6&&#k<=8)?1:((#k>8&&#k<=10)?2:3)

  • S1mon
    S1mon Member Posts: 4,586 PRO

    @EvanReese has a series of 6 videos on expressions and logic in Onshape. I highly recommend watching these since there are a number of useful tricks or things you might not have picked up from other sources.

    https://www.youtube.com/watch?v=J7McsBIEeqc

    Simon Gatrall | Product Development, Engineering, Design, Onshape | Ex- IDEO, PCH, Unagi, Carbon | LinkedIn

  • adi_noyboer004
    adi_noyboer004 Member Posts: 3 PRO

    Well, the series Evan made helped me to debug the subject which is end up to be a syntax issue.

    The nesting should be written like:

    #k>6&&#k<=8?1:(#k>8&&#k<=10?2:3)

  • EvanReese
    EvanReese Member, Mentor Posts: 3,086 PRO
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com