Why is this expression incorrect?

MannyF
MannyF Member Posts: 26 ✭✭

I'm new to OnShape. I'm looking into formulas to drive a design and there are a couple of things I don't fully understand:

OnShape functions do not accept values with units, I assume this is so by design to keep things consistent, and the units must be supplied explicitly. Is there a list that defines the correct spellings? I use British English and was typing millimetre instead of millimeter and so the formula was being flagged as incorrect:

ceil(#WallThick * 3) ❌

ceil(#WallThick / mm * 3) * mm ✅

ceil(#WallThick / millimeter * 3) * millimeter ✅

Also learnt the hard way, units are case-sensitive (it would be nice if OnShape could automatically convert units to lower-case instead of generating an error without further explanation):

ceil(#WallThick / Millimeter * 3) * millimeter ✅

ceil(#WallThick / Millimeter * 3) * Millimeter ❌

Why is the first expression incorrect while he second is correct? For some reason the first instance of 1 mm needs to be enclosed in brackets, but the second does not:

ceil(#WallThick/ 1 mm * 3) * 1 mm ❌

ceil(#WallThick/ (1 mm) * 3) * 1 mm ✅

I'm sure I've just grown a few white hairs over this 😄

Best Answer

  • Matt_Shields
    Matt_Shields Member, Onshape Employees Posts: 1,006 PRO
    Answer ✓

    Sounds like you've basically got it. Always have to be careful about units. Can't add dissimilar units. And can't multiply length by a length and expect to get a length. Things like that.

    If #WallThick is in millimeters, you'll need to divide by mm to get it unitless, then perform a function like ceil() and then multiply again by mm. And yes, spelling and capitalization count 😀

    As for the last question, you need to divide #WallThick by 1mm in order to use ceil(). So, #WallThick/(1 mm) successfully does that. Your first expression basically says #WallThick / 1 * mm which will get you a unit in mm^2.

Answers

  • Matt_Shields
    Matt_Shields Member, Onshape Employees Posts: 1,006 PRO
    Answer ✓

    Sounds like you've basically got it. Always have to be careful about units. Can't add dissimilar units. And can't multiply length by a length and expect to get a length. Things like that.

    If #WallThick is in millimeters, you'll need to divide by mm to get it unitless, then perform a function like ceil() and then multiply again by mm. And yes, spelling and capitalization count 😀

    As for the last question, you need to divide #WallThick by 1mm in order to use ceil(). So, #WallThick/(1 mm) successfully does that. Your first expression basically says #WallThick / 1 * mm which will get you a unit in mm^2.