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.
Nuances of Featurescript 'FeatureList' Inputs
Jonathan_Hutchinson
Member Posts: 91 PRO
I've produced a couple of utility functions that work with features that output (intentionally) multiple unjoined bodies. I'm finding I'm sometimes not able to reliably work with the functions I've made though, as the bodies I am expecting aren't fed in correctly, or are a little bit non-intuitive.
I've attached the pictures below, apologies as they seem to have blown up massively. You can see the slightly odd way that the 'Feature pattern' distinguishes the input. The bodies output from my 'Mirror Custom' is considered to be everything except for the top face, but once I pick that extra face too (which is considered to be the output of a different feature, for some reason) then the linear pattern works.
This seems to be what happens in a few of my featurescripts that take in the FeatureList type, so I'm wondering how I can tune some of these up to work a bit more as expected. Other examples of what I've produced are:
-Transform all the outputs/bodies of a feature, or all 'involved' in a feature I suppose
-Perform a Union of all the outputs of a feature
-Subtract from all the outputs of a feature with another selected body
Appreciate I might need to expand to explain a little bit better still.
I've attached the pictures below, apologies as they seem to have blown up massively. You can see the slightly odd way that the 'Feature pattern' distinguishes the input. The bodies output from my 'Mirror Custom' is considered to be everything except for the top face, but once I pick that extra face too (which is considered to be the output of a different feature, for some reason) then the linear pattern works.
This seems to be what happens in a few of my featurescripts that take in the FeatureList type, so I'm wondering how I can tune some of these up to work a bit more as expected. Other examples of what I've produced are:
-Transform all the outputs/bodies of a feature, or all 'involved' in a feature I suppose
-Perform a Union of all the outputs of a feature
-Subtract from all the outputs of a feature with another selected body
Appreciate I might need to expand to explain a little bit better still.
0
Comments
A repeated use case I am creating is to create a hollow cylinder with thickness, and for it to be divided into a number of convex elements - quite similar to the ones you see above. I have a custom feature which changes the number of divisions for this, ad hoc. Then, let's say I want to array that decomposed cylinder into multiple cylinders. This is handily something I can do with Feature Pattern; I select one of the entities from my decompose feature, and Onshape is being intelligent and performing an action based on the output bodies of a feature above it.
That led me to generate a couple of other examples; mainly I've needed a transform and a mirror to do the same thing; respect whatever the output of the decompose feature, whether it be 6 segments or 10, and transform/mirror all of them in whichever way I am choosing. Does that makse sense?
The requirement to keep all these separate bodies is liekly the main reason I've approached it this way, and I do think it's quite elegant myself. But I feel like I'm probably just one or two lines away from defining it as correctly as it should be - with the above example images which is very nearly working correctly but also just a tad buggy.
If I'm thinking rightly, using just a qCreatedBy wouldn't allow me to get the precise control of what I want to obtain the bodies that a feature, based on the selection of an outputted entity, produced. Even though I'm using qCreatedBy below, I'm using the FeatureList to enable me to get all bodies created by a feature as a selection.
An example - have I maybe overcomplicated something here? This would delete all the bodies created by a feature, based on the selection of one of the bodies.
I guess the question, from a curiosoity point of view, would then be what does the FeatureList type do specifically differently? Maybe I need to do more digging into the specifics of how OnShape features work again. It's sort of a chain of id's IIRC.
So I tried to add some code but that failed spectacularly also how did you add your gif? Does it have to be hosted? Because I did want to do that to better explain my results!
For the gif, you can just drag and drop it into the message.
I don't think I've come across the '->' ; is this ternary-ish or an inline lambda from what my glance at the docs reveals so far? Is the below essentialy passing what the first half evaluates to into after the arrow?
@Alex_Kempen I think you're probably going to be pretty close - so I will try that. The phrasing is close, maybe more like:
"You have a query for some faces on many bodies, related to output from a feature, and you need a query for just the solid bodies that form them".
Could you explain the 'de-duplicate the array using qUnion' step? Phew, all these nested queries sure can start to get out of hand can't they. Thank you both again for assisting here.
The arrow operator (->) passes the value on the left as the first value of the function call on the right:
qUnion has the neat behavior of removing redundant queries from an array of queries. Here's a simple example:
https://cad.onshape.com/documents/00dd11dabe44da2db458f898/w/6c20cd994b174cc99668701f/e/fcfef0ec86c439d44f5dbb3d
Note also the use of map to create an array of individual queries before a final call to qUnion. This is more performant than calling qUnion as you go, e.g. myQuery = qUnion(myQuery, newQuery), as array operations are faster than qUnion (although the performance difference is quite marginal until you get into the hundred or thousand plus range).
See the example I linked in my above post for a concrete example of this implementation.
Is it going to be simplest to change my original function to allow queries as input? Or can I go backwards from a query to a featureList?