Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:
- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
How to use a pre-defined variable as an argument inside a math function?
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.
0
Answers
-
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 Inc1 -
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.0

