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.
Complex Formulas in Variables
robert_melascaglia
Member Posts: 43 EDU
Greetings All
I tried to perform a function that failed; perhaps it is impossible at present or I did it incorrectly. I identified two variables as - #stair_riser = 7.5" and #stair_tread = 9".
I created a sloped line to dimension the pitch with another variable as #stair_pitch to equal - here it is - ArcTan (#stair_riser / #stair_tread) to equal the angle of the pitch.
The Question - can we perform complex math as indicated? Thank you always for your great support and advise - this is a remarkable forum for learning.
I tried to perform a function that failed; perhaps it is impossible at present or I did it incorrectly. I identified two variables as - #stair_riser = 7.5" and #stair_tread = 9".
I created a sloped line to dimension the pitch with another variable as #stair_pitch to equal - here it is - ArcTan (#stair_riser / #stair_tread) to equal the angle of the pitch.
The Question - can we perform complex math as indicated? Thank you always for your great support and advise - this is a remarkable forum for learning.
Tagged:
0
Comments
atan (value is number) returns ValueWithUnits
Arctangent, i.e. inverse tangent.
editting a variable equation in a single line is painful, I think you're ready to move on.
You're one step away from a featurescript which is a great environment for your equations. It doesn't take much to kick off a featurescript which has variables and equations that you can see and work with.
Take your feet out of the cold water and come over here and put'm in some warm water. Try it.
Someone should come up with a 3 minute video doing this.....
The IDE OS built for featurescript is really quite good. I think you'll like it.
Onshape uses the ValueWithUnits type to correctly deal with units. If you just leave `volume` as-is instead of doing `.value*1e9`, `volume / (X*Y)` will come out as the correct value (assuming that X and Z are length values and not raw numbers). If X and Y are currently raw numbers, I think it will be much easier to maintain your code if you make them lengths instead, and use the ValueWithUnits as intended.
If it is not possible to do this, you can convert the volume to millimeters using the following:
But, as I said, I think it will be easier to work with these if you set X and Y to be actual lengths, and then just do the division without any hackery.
Here is some documentation:
https://cad.onshape.com/FsDoc/library.html#ValueWithUnits
And here is an example I put together of how I would organize the code you are writing:
https://cad.onshape.com/documents/754a3d4aaea3998e3633f0c1/w/5e7b3e7733fa80bea100a5b8/e/e811aed1f73d45af81c1846e
tl;dr: let Onshape take care of the units for you instead of trying to manage them yourself. The only time you should need to worry about units is when you want to print out their values, and then it is as easy as just dividing the ValueWithUnits by the unit that you care about.