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

Expressions - Returning a number when using a length

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

floor((#length/2)/60)

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? 

Comments

  • Options
    S1monS1mon Member Posts: 2,374 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.
  • Options
    _anton_anton Member, Onshape Employees Posts: 278
    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.
  • Options
    S1monS1mon Member Posts: 2,374 PRO
    You might also want to look at Linear Pattern Plus. It might solve your needs without needing to write any expressions.

    https://forum.onshape.com/discussion/18076/new-feature-linear-pattern-plus/p1

  • Options
    leecaseyleecasey Member Posts: 34 PRO
    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. 
  • Options
    leecaseyleecasey Member Posts: 34 PRO
    Thank you, the above didnt work but a little change of parenthesis did the job! 

    floor(#length/2/60/(1mm)) 
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,399
    You also don’t need the “1” - just “mm” will do. 
    Senior Director, Technical Services, EMEAI
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,066 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
  • Options
    leecaseyleecasey Member Posts: 34 PRO
    Thanks everyone. 👍 will certainly check out LPP, Evan. 🙂
Sign In or Register to comment.