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.
The most difficult thing in Onshape is rounding a valueWithUnits

Am i going crazy or is there no way to name a part by a rounded valueWithUnits in the user's own workspace units?
0
Comments
yes, thats not a one-line solution, you would have to use roundToPrecision() but it only works for real numbers, so you divide it by unit, round the unitless value to precision, and compose a string of that value and unit name string
but i want the string to be in the user's workspace units
Custom feature execution can't know about workspace units - otherwise, we'd have to regenerate the entire thing any time you change those. The workspace units are basically just for display. If custom feature code determines a part name, it can't depend on workspace units.
You could have your part-naming feature take units and a precision in the UI, and round to that?
There is a way you can get the current workspace units at the time you insert the feature. I learned this trick from Kevin:
https://cad.onshape.com/documents/e0c13dc3836c7dcba155622a/w/c3a138bc21a0284d4afbea62/e/a2290d1b855aec5d8f5af6f3…
Get the current default units when the feature is inserted. This input will default to 1 of whichever units the document is currently using at the time. Note that it only does it when you first insert the feature.
and then, convert and round. Now that I'm looking at this next part, the switch statement might be redundant since the lengthUnit is already a resulting unit.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
thank you. maybe one day there will be getWorkspaceUnits or smth.
EDIT, actually it doesn't work, it's giving me meters always, even though my workspace units are inches.
this did it: