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.
Adding Numbers and valueWithUnits (map)
Hi
I'm trying to assign a variable value which is the addition of two other values where one is a number and the other is the output of an acos(), which makes it a valueWithUnits.
The problem is something similar to:
var ay = 5 + acos(100/102);
Which gives the error as seen on the screenshot.
How can the output of an acos() be made into a number that can be used in this sort of calculation?
Answers
-
acosreturns radians. you need something likevar ay = 5*radian + acos(100/102);0 -
In these sort of situations you can always do
println(acos(100/102));
and see what it's returning.
0 -
Aha, so the issue was more that one number was unitless while the other was not. It works after multiplying radian to the number.
Now, I just have to do the rest of the calculations to see if it results in what I want it to. :)
I'm however still a bit confused about why some things will just print the number and the units while other things will print the whole map. On the screenshot below, I am printing out psie_y which is now a ValueWithUnits (map) after I have multiplied radians to the unitless numbers. On line 103, I am then printing out the value of dy, which is just a diameter but that prints out as just the number and unit. Why do my angles not also just print out as a number and unit?0 -
Maybe because some of those are declared as arrays and they are showing you the full element (map) stored in the array? Not sure actually.
0 -
It's because of the string concatenation - in prepending a string to the
ValueWithUnits, it makesprintlnunable to stringify just the value. You can get around it by doingprint("psie_y "); println(psie_y);.0 -
That would be a notable difference between the different things that I'm printing out here.
I'm used to do math in Matlab/Octave which isn't units aware and just treats everything as a number, so it's a bit of a learning curve to get to the point where I can put my function in a sketch.0





