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.

Variables and math


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?


  • 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,

  • 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.
  • bradley_saulnbradley_sauln Moderator, Onshape Employees, Developers Posts: 361
    @mark_wallström you should also take a look at the integrated cloud app Swift Calcs. I think you will enjoy it
    Engineer | Adventurer | Tinkerer
    Twitter: @bradleysauln

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,012

    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 \ Director, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.