How to use a pre-defined variable as an argument inside a math function?

john270
john270 Member Posts: 2 ✭✭
I've been struggling to figure out how to use a pre-defined variable as an argument inside a math function such as floor(x) or ceil(x).  I can get a real number to work fine as the argument, but every time I use a variable expression such as floor(#length) where the #length has been previously given a decimal real number value through a configuration table, it returns with the error of "Invalid Expression".  Yet I see instructions to do this very thing in several Learning Center videos.  Am I missing a correct syntax format to do this?  I just can't find any documentation of how to use the variables inside functions.  I would appreciate the help.

Answers

  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,279 image
    The problem is that you can't take the floor or ceiling of a length, only a number.  (This is because the floor of a length in inches is different than in meters; if we were to use document units, then changing units would change the design, which is undesirable).  The way to do this computation, if the units you care about are inches is:
    floor(#length / in) * in
    The division converts the length into a number of inches, and the multiplication converts the floored result back to a length.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • john270
    john270 Member Posts: 2 ✭✭
    Yes, thank you for your response. I now realize I need to divide by "in" to get it unitless.  I didn't realize that since I was using that variable as a length for a part, that it carried the units with it.  I was assuming it got treated like "number" in the variable type choices.  I understand now.