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.
What would be the best way to have an assert on a variable
brett_howard659
Member Posts: 6 ✭
Is it possible to give a warning if I'm about to do something stupid with variables?
For example. If I'm designing a block and I put in a line diameter of 12mm and I have a sheave width that is <12mm it would inform me that the sheave width must be greater than line diameter? I mean I suppose I could model the rope and it would visually become obvious but it seems like something simpler would be more effective?
For example. If I'm designing a block and I put in a line diameter of 12mm and I have a sheave width that is <12mm it would inform me that the sheave width must be greater than line diameter? I mean I suppose I could model the rope and it would visually become obvious but it seems like something simpler would be more effective?
0
Best Answers
-
brett_howard659 Member Posts: 6 ✭I wasn't able to view the document you linked but I think I found similar information at this link (https://www.onshape.com/en/resource-center/tech-tips/tech-tip-how-to-use-expressions-for-numeric-fields-in-onshape)... And this is very close and it is what I'm going to do for now... Where I can do something like #sheaveDiameter = #lineDiamter + 1mm. But what I'd prefer is the ability to set the minimum to be that value and anything larger is also allowed.
Actually I think I'm there now...
#sheaveWidth = 5mm
#lineDiameter = 6mm
#finalSheaveWidth = max(#lineDiameter+1mm,#sheaveWidth)
This way if they put in a width too narrow for their intended line it bumps them to 1mm bigger than the line. But if they want the sheave wider they can put that in and that request gets honored too. I think that is about as nice as I can get things.
Thank you all for the ideas!0 -
MichaelPascoe Member Posts: 1,989 PRO
The max function works in this case. If you ever need more detailed statements instead of a simple function, ternary conditional operators are the way to go. So in the statement below, if the modified line diameter is greater than the sheaveWidth, return the modified diameter; else, return the sheaveWidth.
#finalSheaveWidth = (#lineDiameter+1mm) > #sheaveWidth? #lineDiameter+1mm : #sheaveWidth
See this post to get started Ternary Conditional Operators (Quick Guide)
And here are the official help tutorials in the learning center Variables and Expressions Course
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴0
Answers
Actually I think I'm there now...
#sheaveWidth = 5mm
#lineDiameter = 6mm
#finalSheaveWidth = max(#lineDiameter+1mm,#sheaveWidth)
This way if they put in a width too narrow for their intended line it bumps them to 1mm bigger than the line. But if they want the sheave wider they can put that in and that request gets honored too. I think that is about as nice as I can get things.
Thank you all for the ideas!
The max function works in this case. If you ever need more detailed statements instead of a simple function, ternary conditional operators are the way to go. So in the statement below, if the modified line diameter is greater than the sheaveWidth, return the modified diameter; else, return the sheaveWidth.
#finalSheaveWidth = (#lineDiameter+1mm) > #sheaveWidth? #lineDiameter+1mm : #sheaveWidth
See this post to get started Ternary Conditional Operators (Quick Guide)
And here are the official help tutorials in the learning center Variables and Expressions Course
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴