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.

Expressions - Returning a number when using a length

leecaseyleecasey Member Posts: 33
Hi I'm having a bit of trouble generating an integer for a pattern number from an expression which is using an length (mm). 


I'm assuming the issue is incompatible types but not sure how to solve it. Is there any way to cast #length as an int? 


  • S1monS1mon Member Posts: 1,984 PRO
    You can divide by 1 mm to get rid of the units, but I'm a little unclear how you're trying to use this calculation.

    I didn't test this, but something like this should work:
    floor((#length/2)/60)/(1 mm)

    If you ever change the units of the document it's going to break, and I can't quickly think of a way to make this so that it will just get rid of the units in a universal way.
  • _anton_anton Member, Onshape Employees Posts: 170
    Simon is correct. FWIW, though, I'd flip the logic around: make a variable like #number_of_instances, then make a #length variable computed from that. That makes it easy to update things and saves you from having to floor() anything.
  • S1monS1mon Member Posts: 1,984 PRO
    You might also want to look at Linear Pattern Plus. It might solve your needs without needing to write any expressions.


  • leecaseyleecasey Member Posts: 33
    Unfortunately that didn't work. Here's a better explanation of what I'm trying to achieve. I need to pattern some holes on this rail, the pattern must be central to the rail, hence why I'm dividing the length by 2. So I just want to generate the number of holes in the pattern from the length in mm. 
  • leecaseyleecasey Member Posts: 33
    Thank you, the above didnt work but a little change of parenthesis did the job! 

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,964
    You also don’t need the “1” - just “mm” will do. 
    Senior Director, Technical Services, EMEA 
  • Evan_ReeseEvan_Reese Member Posts: 1,984 PRO
    This is exactly the kind of situation I wrote Linear Pattern Plus for (as Simon mentioned). in your case, is the 60 the hole spacing? if so, you could also just make it 60mm and that'd do it. length/length = number
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • leecaseyleecasey Member Posts: 33
    Thanks everyone. 👍 will certainly check out LPP, Evan. 🙂
Sign In or Register to comment.