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.

Options

Variables and math

Hi,

First; Onshape is the best thing since sliced bread, period. What you have done is extraordinary, thank you.

I'm a "make variables for everything"-kinda guy. Is there a reason we can't do math with variables? For example, I have variable #pistondiameter and I want to make a dimension be #pistondiameter+2, which can't be done.

Can it be so that I am doing something wrong?

Comments

  • Options
    viruviru Member, Developers Posts: 619 ✭✭✭✭
    edited December 2016
    @mark_wallström, You can do math with variables. Currently you are facing problem in your dimension having varible because your variable expression is not Valid ( Not consisting with bracket before unit ). Please add bracket in your dimension it will definitely work. You should write (#pistondiameter+2) before unit
    Please refer below video for more detail,


  • Options
    mark_wallströmmark_wallström Member Posts: 4
    Fantastic, thank you viru. I also think I made an error in putting in the value for the variable as [mm] and added a dimensionless number to it (+2 instead of +2mm) in the expression.
  • Options
    bradley_saulnbradley_sauln Moderator, Onshape Employees, Developers Posts: 373
    @mark_wallström you should also take a look at the integrated cloud app Swift Calcs. I think you will enjoy it
    https://www.swiftcalcs.com/#product
    Engineer | Adventurer | Tinkerer
    Twitter: @bradleysauln


  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    @mark_wallström

    Thanks for the kind words!  Onshape supports all kinds of math in variables, other feature parameters, and dimensions (see https://cad.onshape.com/help/#numeric-fields.htm) and you can even write you own functions using FeatureScript.

    Your diagnosis is correct -- Onshape is strict about not mixing units (you can add an inch to an inch or a meter, but not to an angle or a unitless number) so if #pistondiameter is a length, then you should add 2mm to it.

    The parenthesis (bracket) is not necessary.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Options
    john_david_dunsonjohn_david_dunson Member Posts: 4
    This should be added to the Variable page in the help library.  I was ripping my hair out trying to add numbers to variables.  I'm a beginner, but nowhere else that I've encountered have I had to specify units in dimensions.  So it's easy to multiply variables, but it's not at all obvious that specifying units would be required for that one thing.  To me anyway.
    Thanks bunches
  • Options
    john_david_dunsonjohn_david_dunson Member Posts: 4
    @mark_wallström

    Thanks for the kind words!  Onshape supports all kinds of math in variables, other feature parameters, and dimensions (see https://cad.onshape.com/help/#numeric-fields.htm) and you can even write you own functions using FeatureScript.

    Your diagnosis is correct -- Onshape is strict about not mixing units (you can add an inch to an inch or a meter, but not to an angle or a unitless number) so if #pistondiameter is a length, then you should add 2mm to it.

    The parenthesis (bracket) is not necessary.

    This should be added to the Variable page in the help library.  I was ripping my hair out trying to add numbers to variables.  I'm a beginner, but nowhere else that I've encountered have I had to specify units in dimensions.  So it's easy to multiply variables, but it's not at all obvious that specifying units would be required for that one thing.  To me anyway.
    Thanks bunches
Sign In or Register to comment.