Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Trouble Patterning a FeatureScript
robert_morris
OS Professional, Developers Posts: 168 PRO
Hello all,
I've been working on a new FeatureScript, and have it mostly working, but now I'm having a little trouble getting it to work with the Pattern tool.
I found the "getRemainderPatternTransform()" and "transformResultIfNecessary()" functions and have added them to my code.
Now when I try to pattern my feature, it will pattern the sketches in the FeatureScript, but the actual solid bodies still don't get replicated.
I'm not sure what I'm missing or doing wrong, so if anybody can help me out here, that would be great.
I've made a stripped down example of my code public, you can access it here:
https://cad.onshape.com/documents/ffb2867fa9892c78256b73fd/w/e73b0aaba0a8f6e661b4c33a/e/4647be21759905a925687466
Thanks,
I've been working on a new FeatureScript, and have it mostly working, but now I'm having a little trouble getting it to work with the Pattern tool.
I found the "getRemainderPatternTransform()" and "transformResultIfNecessary()" functions and have added them to my code.
Now when I try to pattern my feature, it will pattern the sketches in the FeatureScript, but the actual solid bodies still don't get replicated.
I'm not sure what I'm missing or doing wrong, so if anybody can help me out here, that would be great.
I've made a stripped down example of my code public, you can access it here:
https://cad.onshape.com/documents/ffb2867fa9892c78256b73fd/w/e73b0aaba0a8f6e661b4c33a/e/4647be21759905a925687466
Thanks,
Tagged:
0
Best Answers
-
elif Onshape Employees Posts: 53Hi Robert,
From a quick experiment I noticed that if you make the extrude do a NEW instead of an ADD it works.
I recommend doing the feature pattern followed by a single boolean at the end.
Feature pattern expects the body to be merged to (booleanScope) be patterned as well. As it cannot find an instance of it, it cannot merge with it and therefore fails to pattern the extruded body. Because it can pattern the sketch, it partially succeeds and therefore the feature does not fail with an error.
6 -
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Designing for feature pattern indeed takes some thought – Since a feature pattern just calls your feature function, with only the result of getRemainderPatternTransfrom differing, the "correct" thing to do is going to vary based on what the feature does.
In your case, you're doing an "Up to body" extrude, and it seems the desired behavior would be to maintain the "Up to body" condition for the patterned instances (rather than maintaining the exact geometry). So, the change I'd recommend is actually just to move transformResultIfNecessary before the extrude (so it's just transforming your sketch), which I did in this document:
https://cad.onshape.com/documents/585c71ff8a333e1044f8e8c8/w/7c00d6970aadd024a22548ec/e/32b29334bff263d829820503
Let us know if this adjustment works for your non-stripped-down case!
5
Answers
From a quick experiment I noticed that if you make the extrude do a NEW instead of an ADD it works.
I recommend doing the feature pattern followed by a single boolean at the end.
Feature pattern expects the body to be merged to (booleanScope) be patterned as well. As it cannot find an instance of it, it cannot merge with it and therefore fails to pattern the extruded body. Because it can pattern the sketch, it partially succeeds and therefore the feature does not fail with an error.
In your case, you're doing an "Up to body" extrude, and it seems the desired behavior would be to maintain the "Up to body" condition for the patterned instances (rather than maintaining the exact geometry). So, the change I'd recommend is actually just to move transformResultIfNecessary before the extrude (so it's just transforming your sketch), which I did in this document:
https://cad.onshape.com/documents/585c71ff8a333e1044f8e8c8/w/7c00d6970aadd024a22548ec/e/32b29334bff263d829820503
Let us know if this adjustment works for your non-stripped-down case!
Both methods (extrude NEW or transforming the sketch) yield partial success with my full code.
The problem now seems to be that since I'm also adding other things on top of those first extrusions, those items aren't being transformed as well.
It looks like I will have to rethink how some of the code is organized in order to get it to fully work with patterns. Either by doing all the sketches at once and transforming those, or messing around with booleans of the individual features.
This FeatureScript doesn't really need to work with patterns, but I thought i'd do it for completeness sake.
FWIW, here is a link to the full code of what I'm working on:
https://cad.onshape.com/documents/2972a375d9fd3b741d7cc02a/w/45408693c3984999d8c8ff22/e/403280a8c811319478bddf50
It's for making Mounting Bosses used in molded plastic parts.
I borrowed some of the code from Neil Cooke's Screw Boss feature, modified a couple of things, and expanded on it to allow for other types of boss.
Thanks for the pointers.
I took a look at the hole feature and borrowed some of the computeCSys() code in there to do the transformation of the locations, and with some healthy debug() usage, I got everything working.