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 in Patterns

thomas_kozakthomas_kozak Member Posts: 38 ✭✭
edited June 2023 in Community Support
Is it not possible to use a variable as the number of repetitions in a pattern?  When I create a circular pattern I can define it using a variable, but the variable is replaced with a static number once the pattern is finalized.  At that point it won't accept a variable any more.

Best Answer

Answers

  • thomas_kozakthomas_kozak Member Posts: 38 ✭✭
    Thanks!  I hadn't thought to try a face pattern, which is a suitable workaround for what I'm trying to do in this case.
  • juanpintomjuanpintom Member Posts: 2
    Hi all!, what about this bug? I need to use a #variable on number of repetitions (3x) :S

    Thanks :)
  • juanpintomjuanpintom Member Posts: 2
    Hi all!, what about this bug? I need to use a #variable on number of repetitions (3x) 

    Thanks
  • richard_gainrichard_gain Member Posts: 1 ✭✭
    Hi I'm trying to grid a parametric grid of circles and have run into this problem as well. Any progress on this bug? Thanks, Richard Gain
  • florianflorian Member, OS Professional Posts: 110 ✭✭✭
    I think this still needs fixing. It can't be that hard.

    @lougallo I think I reported this a few "years" back as well.

  • florianflorian Member, OS Professional Posts: 110 ✭✭✭
    Thank you very much @kevin_o_toole_1 for the great answer.

    I first thought it would still be impossible, as I need to pattern a sketch vertex. But with the help of a zero offset surface and a 3D spline (wich is a straight line if you select only two vertices) you can pattern it and use the endpoint of the patterned spline as the vertex later. Here is the example:



    …It is great to hear that my designs will be the same in a few years time, even if the underlying feature logic changes.
  • emagdalenaC2iemagdalenaC2i Member, Developers, Channel partner Posts: 858 ✭✭✭✭✭
    Hi @florian

    Do you know that you can create an array feature of a sketch??

    A sketch, a variable or an extrude are all features that you can use in your arrays.

    Take a look of this sample https://cad.onshape.com/documents/556785024e8ea12b4ff1a004/w/45110c3cc4d2d6e8047223c3/e/969f8e15e7ed8c4f45eb16b6
    Un saludo,

    Eduardo Magdalena                         C2i Change 2 improve                         ☑ ¿Por qué no organizamos una reunión online?  
                                                                         Partner de PTC - Onshape                                     Averigua a quién conocemos en común
  • florianflorian Member, OS Professional Posts: 110 ✭✭✭
    @emagdalenaC2C

    True. That works fine as well. But you cannot do it selectively. Still pretty useful!
  • RyanAveryRyanAvery Member Posts: 93 EDU
    For this case we recommend the linear pattern feature. Within that feature, Face pattern, Body pattern, and Feature pattern will all do the job.

    Sketch patterns are extremely flexible. They generate a set of sketch entities and constraints, but after that, you can remove any constraint, add more constraints, or even delete the patterned entities. Unfortunately, this means changing the pattern count to a smaller number, then back to the same number, will destroy any such changes and leave you with a different model!

    Doing that change with a variable would violate one of the core principles of Onshape's architecture, deterministic regeneration, which means than the same feature tree will build the same way every time, regardless of what steps you took to create it (and that it will stay that way eternally through all versions of Onshape!). This is something which is demonstrably absent in other CAD systems, but is a critical component of any system which has real-time collaboration, and will also be a key piece of Onshape's upcoming implementation of configurations.

    The linear pattern and circular pattern features are less flexible in this extent, but are fully deterministic so it's safe to dynamically control it with a variable in your feature tree.

    (To be clear, this doesn't mean we'll never be able to control sketch patterns with a variable. It just means that to do so, we need to change the internal representation of sketch entities and sketch patterns so that this information is not destroyed, which would be a reasonably large change that we haven't prioritized)
    I don't mean to be rude but I think this is a bit of a cop out. Currently, if you make circle 5 cm north of origin and then do a circular pattern about the origin with a value of 3x, you will get this: 


    Then, in a second, later sketch, reference the center points of those circles and make larger circles from them. (I use the center-point-circle tool 3 times to make this next image, once at each of the centers): 



    Then I go back to sketch 1 and I change the 3x to a 5x: 


    The only problem here is that I had to open sketch one, find the actual place where it said "3x" inside that sketch, double click it, and then replace the 3 with a 5. Instead of doing all that, it would be easier if there was a variable that stored the number I wanted to use which I could change easily. This has nothing to do with the philosophy of a cad program. Any time I can go find a place which takes a number input (which can be changed at any time) that place should also accept a variable. 

    I'm sure someone is looking at this last image that has 3 large circles and 2 small circles (which of course looks goofy and undesirable) and is thinking "ah, its good we don't allow this" but you're wrong--you do allow this, just not with a variable, which is what we are requesting in this thread. 
  • RyanAveryRyanAvery Member Posts: 93 EDU
    This seems like it should be addressed and could be fixed pretty easily. 
  • 3dcad3dcad Member, OS Professional, Mentor Posts: 2,470 PRO
    @RyanAvery
    I agree that any number should be able to replace with variable. But in this case, why are you using two sketches for those circles? I would also consider doing the pattern as face/feature pattern and keep the sketch as simple as possible.
    //rami
  • RyanAveryRyanAvery Member Posts: 93 EDU
    I did it to show as an example; I didn't think too much about making my example optimal. 
  • jmsaltzmanjmsaltzman Member Posts: 16 ✭✭
    Hey does anybody know where I can find the feature request to upvote?
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    @jmsaltzman as a pro user you can "contact support" under the help menu in Onshape and request an enhancement.
    Senior Director, Technical Services, EMEAI
  • GHamszGHamsz Member Posts: 32
    I ran into the same problem, and spent hours trying to figure out why my configuration variables weren’t being honored in the sketch. Thankfully, I found this post, and was able to modify the design to use a circular pattern on two features to create the part I wanted. Now the configuration tables/variables can be used to create the part on the fly.

    in the pic below, I created two cylinder features, and created a circular pattern on the smaller cylinder driven by configuration variables to cut the teeth.


  • GHamszGHamsz Member Posts: 32
    I’m trying to use a linear pattern on a feature, and have run into another issue. Yes, variables work in the pattern count, but if I use something like floor(#WallLength/16in) it fails. 

    After playing around with it for a while, I believe it has a problem with the fact that the result of the operation is a length. If I make WallLength a number, and divide by the integer 16, it works.

    Is there any way around this, or am I missing something?
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    GHamsz said:
    I’m trying to use a linear pattern on a feature, and have run into another issue. Yes, variables work in the pattern count, but if I use something like floor(#WallLength/16in) it fails. 

    After playing around with it for a while, I believe it has a problem with the fact that the result of the operation is a length. If I make WallLength a number, and divide by the integer 16, it works.

    Is there any way around this, or am I missing something?
    hmmm - I thought that should have worked, with the units cancelling each other out - floor((#WallLength/16)/in) definitely works though.
    Senior Director, Technical Services, EMEAI
  • GHamszGHamsz Member Posts: 32
    I Figured it out...
    #WallLength/16in doesn’t work, but
    #WallLength/(16in) does

    I believe the first case is applying “in” to the result of #WallLength/16. It’s my understanding #WallLength/16 is invalid. 
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    That makes sense (to Onshape) since 16in is equivalent to 16 * in so the parentheses are required to make sure it evaluates properly. 

    Therefore #WallLength/16in = (#WallLength/16)*in = value in^2 which is an area not a length. 
    Senior Director, Technical Services, EMEAI
  • fstfst Member Posts: 42 ✭✭
    For this case we recommend the linear pattern feature. Within that feature, Face pattern, Body pattern, and Feature pattern will all do the job.

    Sketch patterns are extremely flexible. They generate a set of sketch entities and constraints, but after that, you can remove any constraint, add more constraints, or even delete the patterned entities. Unfortunately, this means changing the pattern count to a smaller number, then back to the same number, will destroy any such changes and leave you with a different model!

    Doing that change with a variable would violate one of the core principles of Onshape's architecture, deterministic regeneration, which means than the same feature tree will build the same way every time, regardless of what steps you took to create it (and that it will stay that way eternally through all versions of Onshape!). This is something which is demonstrably absent in other CAD systems, but is a critical component of any system which has real-time collaboration, and will also be a key piece of Onshape's upcoming implementation of configurations.

    The linear pattern and circular pattern features are less flexible in this extent, but are fully deterministic so it's safe to dynamically control it with a variable in your feature tree.

    (To be clear, this doesn't mean we'll never be able to control sketch patterns with a variable. It just means that to do so, we need to change the internal representation of sketch entities and sketch patterns so that this information is not destroyed, which would be a reasonably large change that we haven't prioritized)
    Thanks for the explanation, this makes sense. Not being able to parameterize the patterns is highly limiting though and prevents many interesting use cases (like using parametric sketches as basis to loft bodies which's shape can hugely vary based on the sketches - things that would be very hard to make in a parametric manner on the feature level).
    Would it be possible to provide an option to convert the pattern into "normal" geometry? Then it wouldn't be a pattern anymore and people can remove constrains, modify stuff etc. at will. The pattern would in this case more be a template that allows to rapidly produce geometry that can then manually be fine tunes.
    That way the patterns would have a very defined behavior as long as they are patterns - and could thus also be parameterized.
    So people have the choice - leave patterns patterns as a parametric feature or just use them as a template, convert them to plain geometry and modify at will.

    I used several sketches as basis for a loft and manually changed the pattern count in all sketches. It worked perfectly, changing the numbers was really all I had to do, the loft adapted as expected! As long as one has to do this manually in a lot of sketches it is super tedious though - but it shows that it works as long as one doesn't manually remove constaints etc. and keeps the patterns as patterns.
    Would be so good to be able to use a variable or change the value as part of a configuration!.

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,310
    This is now implemented.
    Senior Director, Technical Services, EMEAI
This discussion has been closed.