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.
Best method to select multiple sketches and iterate through them
seaelem
Member, Developers Posts: 6 ✭✭
Hi Folks,
Having just started using feature Script, I was looking for guidance on how to select multiple sketches in order to do something useful with them. The trivial example that I have seen discussed (but I'd not found an example of) was doing an extrusion operation on multiple sketches in one step.
I have posted my method of doing an extrusion on multiple sketches below in order to show:
Carl.
Having just started using feature Script, I was looking for guidance on how to select multiple sketches in order to do something useful with them. The trivial example that I have seen discussed (but I'd not found an example of) was doing an extrusion operation on multiple sketches in one step.
I have posted my method of doing an extrusion on multiple sketches below in order to show:
- Use of the "EntityType.FACE" filter to select multiple faces for extrusion
- Use of "evaluateQuery" in order to break out that multi-select into useful transient queries. From what I've read there's probably a better way of doing this but so far I can't make one work.
- Looping through each sketch query with an index and running the extrude feature method for each one.
/* * Who: Carl Morley * Date: 5 June 2016 * Title: Extrude multiple sketches with the same depth simultaneously * Description: A simple method of extruding multiple sketches to the same depth at once. * Written only as experiment of how to do very basic multi-sketch selection and operations in Feature Script. */ annotation { "Feature Type Name" : "Multi-Extrude" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Capture user input on depth of extrusion and which faces to extrude. annotation { "Name" : "Depth" } isLength(definition.myDepth, LENGTH_BOUNDS); annotation { "Name" : "Faces and sketch regions to extrude", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 3 } definition.myFaces is Query; } { // Evaluate the user query of extrusion faces into a collection of temporary queries. // I suspect there's a better way to do use the 'myFaces' definition directly and does not require the evaluation call. // But at this stage not sure what that better method is! const allSketches = evaluateQuery(context, definition.myFaces); // Set a count to zero for id suffix var i = 0; // Loop through all the sketches and work on each one in turn for (var aSketch in allSketches) { // Increment the count i += 1; // Call the basic extrusion method, incrementing the id by 'i' and using each sketch and the universal 'myDepth' extrude(context, id + "extrude" + i, { "entities" : aSketch, "endBound" : BoundingType.BLIND, "depth" : definition.myDepth }); } });Kind regards,
Carl.
0
Comments
Having just started using feature Script, I was looking for guidance on how to select multiple sketches in order to do something useful with them. The trivial example that I have seen discussed (but I'd not found an example of) was doing an extrusion operation on multiple sketches in one step.
I have posted my method of doing an extrusion on multiple sketches below in order to show:
- Use of the "EntityType.FACE" filter to select multiple faces for extrusion
- Use of "evaluateQuery" in order to break out that multi-select into useful transient queries. From what I've read there's probably a better way of doing this but so far I can't make one work.
- Looping through each sketch query with an index and running the extrude feature method for each one.
Hopefully this is useful to someone and at the same time if anyone has input on whether there's a better way to break out sketch queries other than running the query evaluation method I'd be interested. In all honesty I'm not clear on what that evaluation actually does - other than it seems to work!Kind regards,
Carl.
What you've got looks like the right pattern to be using, and pretty much exactly how I'd write it if you want that behavior, assuming that the behavior you want is for each region to be extruded normal to its face.
Another way of writing the inner part of your loop (which is essentially what ends up getting called in the extrude feature that you've called directly) is:
However, in most cases you don't need to split up a query before passing it into another feature or operation.
Let's say you instead wanted to extrude all the faces in the same direction, according to the sketch plane of the first face. You could then instead write your whole feature as:
A few closing thoughts:
"Filter" : EntityType.FACE && SketchObject.YES
. Alternatively, you can allow non-sketch planes by using"Filter" : EntityType.FACE && GeometryType.PLANE
, and replace evOwnerSketchPlane with evPlane.This looks right -- given that your faces may not be all parallel and extrude currently only extrudes in one direction, I don't think there's a better way to do what you are doing.
Edit -- ah, I didn't see Kevin's much better response to the other copy of your post.
Thanks Ilya & Kevin,
It's good to be on board and I'm enjoying getting my head around the concepts of FeatureScript.
Confirmation that I need to evaluate a query in order to get to specific entities is really helpful and the
SketchObject
andGeometryType
filters solve the next problem I was encountering, much appreciated.Kind regards,
Carl