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.

How should I reference each body made by a pattern

jason_1jason_1 Member Posts: 25 PRO
I'm trying to make a sample featurescript where a body is patterned and each body created by that pattern is set to a different color.

I've successfully done the similar thing by creating the bodies within a for loop that also sets their PropertyType.APPEARANCE. 
And I've successfully gotten the bodies to patten using curvePattern(), but when I try to set their colors I end up coloring all the bodies made by that pattern at once.

What's the best way to reference each instance of the body created by a pattern? Is there some attribute I should be calling? Or some way to put them all into an array?

Comments

  • jason_1jason_1 Member Posts: 25 PRO
    edited February 2021
    I've now gotten it to mostly work using qNthElement(qCreatedBy(id, EntityType.BODY), i) in which the id is the id of the seed part (and the parent id of the pattern) and i increments from 0 to instanceCount of the pattern.

    I'm also reading now about forEachEntity() and wondering if this is actually the function I should be using somewhere
  • lanalana Onshape Employees Posts: 706
    @jason_1

    qNthElement(qCreatedBy(id, EntityType.BODY), i)   will work by virtue of pattern instances being internally processed in the correct order.  It might be more convenient to use qPatternInstances query.  forEachEntity processing is not useful in this case - it would be if you wanter to make geometry changes on each entity separately. E.g. if you wanted to hollow patterned parts with thickness depending on i.
Sign In or Register to comment.