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 strip the units from a length?
jackson_king
OS Professional Posts: 80 PRO
Hi All,
Is there a way to strip a length of it's units so the decimal number can be used in a "ceil(#/#)" equation?
I am trying to use configs to create an expanded metal/grating generation part studio and have it working well except for getting the desired sheet size to auto size. I am using measure distance FS to get the lengths and widths for the distance of the pattern and am trying to use that measure distance number in the ceil function to drive the instance count. In this case, ceil(#Desired_Length/#Length) or ceil(#Desired_Width/#Width).
Here's the document:
https://cad.onshape.com/documents/07f282dcddf2935fa6750b71/w/2c0dd72f79a3f141eac8e0ae/e/de6fa0c8db0a64009288fb77
Thanks in advance!
Jackson
Is there a way to strip a length of it's units so the decimal number can be used in a "ceil(#/#)" equation?
I am trying to use configs to create an expanded metal/grating generation part studio and have it working well except for getting the desired sheet size to auto size. I am using measure distance FS to get the lengths and widths for the distance of the pattern and am trying to use that measure distance number in the ceil function to drive the instance count. In this case, ceil(#Desired_Length/#Length) or ceil(#Desired_Width/#Width).
Here's the document:
https://cad.onshape.com/documents/07f282dcddf2935fa6750b71/w/2c0dd72f79a3f141eac8e0ae/e/de6fa0c8db0a64009288fb77
Thanks in advance!
Jackson
Tagged:
1
Best Answers

Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,639@jackson_king
You don't need to strip the units at all! A length divided by another length is just a number, so the expression you've proposed is perfectly fine. It looks like you haven't tried it out yet, give it a shot in your document and it should work. (I tried it myself and set one of the pattern instance counts to 'ceil(#Length/#Width)' and it worked as expected):
https://cad.onshape.com/documents/81e1def03ed3ef2f11e46393/w/cb6c92ffab42a4ee16d61ecc/e/cdd309359c16357ecef84025
Jake Rosenfeld  Modeling Team6 
ilya_baran Onshape Employees, Developers, HDM Posts: 1,049A better way of doing this is dividing by the unit. If you want the number of inches in #length, use #length / in
Getting the value like @konstantin_shiriazdanov proposed will always give you the length in whatever internal units we're using, which may not be what you want.
Ilya Baran \ Director, Architecture and FeatureScript \ Onshape Inc6
Answers
You don't need to strip the units at all! A length divided by another length is just a number, so the expression you've proposed is perfectly fine. It looks like you haven't tried it out yet, give it a shot in your document and it should work. (I tried it myself and set one of the pattern instance counts to 'ceil(#Length/#Width)' and it worked as expected):
https://cad.onshape.com/documents/81e1def03ed3ef2f11e46393/w/cb6c92ffab42a4ee16d61ecc/e/cdd309359c16357ecef84025
Jackson
Getting the value like @konstantin_shiriazdanov proposed will always give you the length in whatever internal units we're using, which may not be what you want.
Jackson
Website: ovyl.io
Instagram: @evan.reese.designs
It might be easier to answer if we had additional detail about what your user inputs are and what you are trying to do with them
As a learning exercise, I'm trying to plot points to a sine wave like this:
Amplitude, frequency, and x are all valueWithUnits (lengths), and I think that's what I want, but cos() wants an angle, not the unit mashup I have. Should I change all of them to just values? if so, how do I get the right units without the user having to think about it?
Website: ovyl.io
Instagram: @evan.reese.designs
Issues with units usually indicate an issue with the equation itself; if you were solving this equation on paper for a given x value, you would expect all the units to cancel appropriately to give you the right answer. So to tackle it in parts:
(e^(decay/100*x)): this is a scale factor, and should be unitless. Since `x` is a distance, I would expect `decay` to be in distance units, describing how far along the xaxis you want this scale factor to be (e^(1/100))
cos(x*frequency*degree): As this is right now, I would expect "frequency" to be in inverse distance units (i.e. "1 / distance"), and that (frequency * degree) forms a statement of "for every (1 / frequency), the cos wave changes by one degree". I do not think this is the intention, it seems that you are having the user supply "frequency" meaning "how frequently does the cos wave pass through a full cycle". In which case the correct equation would be: cos(x*(360*degree/frequency)); and you will see here that that the units just fall out correctly, without having to strip anything of its units.
Website: ovyl.io
Instagram: @evan.reese.designs