Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

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?

Best Answers

  • brett_howard659brett_howard659 Member Posts: 6
    Answer ✓
    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!
  • MichaelPascoeMichaelPascoe Member Posts: 1,989 PRO
    edited August 2023 Answer ✓

    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 🔴

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,688
    Configuration variables have limits
    Senior Director, Technical Services, EMEAI
  • brett_howard659brett_howard659 Member Posts: 6
    Hrm...  I'll read more about configuration vars...  If the limits can be a function of another var that sounds like exactly what I'm looking for. 
  • eric_pestyeric_pesty Member Posts: 1,891 PRO
    Hrm...  I'll read more about configuration vars...  If the limits can be a function of another var that sounds like exactly what I'm looking for. 
    Unfortunately the limits are not "adjustable" based on other inputs (at least last time I checked...). There are a number of improvement requests related to adding "logic" to configurations (to control available options based on another input)
  • S1monS1mon Member Posts: 2,989 PRO
  • brett_howard659brett_howard659 Member Posts: 6
    Answer ✓
    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!
  • MichaelPascoeMichaelPascoe Member Posts: 1,989 PRO
    edited August 2023 Answer ✓

    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 🔴
  • brett_howard659brett_howard659 Member Posts: 6
    Oh rock on...  I'm totally used to ternary operators...  I'm an EE and Software guy by degrees so I'm slowly trying to learn this ME stuff too.  Thank you guys for all the pointers!
Sign In or Register to comment.