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 selecting shapes,edges using query/filters
fredrik_tärnell
Member Posts: 29 ✭✭
Have a feature script that imports an excel file with some vertices and creates a sketch with a rectangle and a few circles inside that rectangle that I want to extrude.
Tried long and (too) hard to get it to work.
At the moment my script is not doing what I want.
The extruding results in a filled rectangle and not with the holes (from the circles) which is really what I want.
Understand this is because I do:
But I'm failing to understand how I could select only the rectangle and exclude the faces of the circles.
It would have been nice to use the names of the id's but I cannot get it to work.
Tried placing all my circle id's in an array and go from there but I't not working.
This is what I have come up with so far. Playing with the entitiesX variables and debug to figure out how to select (actually excluding them in the extrude) my inner_circles
https://cad.onshape.com/documents/4da2343209e7255f07f4540e/w/a782e962107ee455b65497a8/e/531534ac2a86a8ec2be12f2f
Any ideas?
Thanks!
Tried long and (too) hard to get it to work.
At the moment my script is not doing what I want.
The extruding results in a filled rectangle and not with the holes (from the circles) which is really what I want.
Understand this is because I do:
var entities = qEverything(EntityType.FACE);
var entities2 = qSketchFilter(entities, SketchObject.YES);
But I'm failing to understand how I could select only the rectangle and exclude the faces of the circles.
It would have been nice to use the names of the id's but I cannot get it to work.
Tried placing all my circle id's in an array and go from there but I't not working.
This is what I have come up with so far. Playing with the entitiesX variables and debug to figure out how to select (actually excluding them in the extrude) my inner_circles
https://cad.onshape.com/documents/4da2343209e7255f07f4540e/w/a782e962107ee455b65497a8/e/531534ac2a86a8ec2be12f2f
Any ideas?
Thanks!
Tagged:
0
Comments
qSketchRegion (featureId is Id, filterInnerLoops is boolean) returns Query
A query for all fully enclosed, 2D regions created by a sketch.
featureId
<a rel="nofollow" href="https://cad.onshape.com/FsDoc/library.html#Id">Id</a>
The feature id of the
Sketch
being queried.filterInnerLoops
<a rel="nofollow" href="https://cad.onshape.com/FsDoc/variables.html#boolean">boolean</a>
Optional
Specifies whether to exclude sketch regions fully contained in other sketch regions. A region whose border has a vertex or edge on the outside boundary is not considered "contained." Default is false.
Yes, this worked.
qSketchRegion(sketchID, true);
It solved the issue partially.
My biggest issue is trying to figure out how to select/query/filter the shapes I do need.
My sketch container an inner and an outer circle for each vertices and I would like to add the outer circle faces to my extrude as well. So really sketchRegion and all the faces named circle_inner* but wild carding does seem to be an existing option?
I.e the part I colored yellow (and all of them).
Started with sketch1 and put my inner circles there. Extrudes successfully..
Create sketch2 and places my outer circles there. Same result. Need to select all the id's "outer_circle"* at this stage?
OR could I go for selecting all shapes of the type = circle somehow?
The yellow part I highlighted in the previous screenshot
Sketch 1 should include the surrounding rectangle and the outer circles
Sketch 2 should include the outer circles and the inner circles
Both sketches can then be queried with qSketchRegion(...true...) to get the desired content of the two extrudes (Sketch 1 to the shorter depth, Sketch 2 to the longer depth).
A single sketch would be much harder to work with, since querying the "right" regions isn't trivial. With a sketch, the functions you call draw lines, but the outputs you want to query are regions. If you don't segregate by sketch, you would have to do a lot of tricky work using queries like qContainsPoint() to get the correct regions. There's a similar tradeoff when making this without FeatureScript: With one sketch, you would have to manually pick a bunch of sketch regions to extrude by selecting them, but with two sketches, you can just click the full sketches to extrude.
Let us know if you have further questions!
Now I just have to make a boolean merge of all the parts.
Not sure if it's an old feature request or a duplicate but....
Feature reqs:
- Generate corresponding feature script code during edit in the UI to simplify further. Probable a quite large request.
- Allow one to store id's in an array during the creation of shapes to pass them into opExtrude as an example.
First tried to get all bodies and use only tools and not targets.
Was hoping since I select the target as the one with the rectangle (large solid) they do intersect so they should be possible to merge into a single solid..
But.... NOT
If I use the UI it becomes obvious that union only uses the tools and not targets. So I'm guessing the targets is not taken into account and there is no intersecting solids. So how can I merge all solids in the context?
But this generates :
Since:
returns 90 bodies which are not all solids (or maybe none are??)
You are running into an issue because our UNION merges all the tools together, as documented in the following:
https://cad.onshape.com/FsDoc/library.html#opBoolean-Context-Id-map
You could do "tools" : qUnion([tools, targets]) and not set "targets at all" and your opBoolean would work as expected.
The better way to do this might be to use 'extrude' instead of 'opExtrude' and supply the following in the definition map:
"operationType" : NewBodyOperationType.ADD,
"defaultScope" : false,
booleanScope : qCreatedBy(id + "extrude1", EntityType.BODY)
This is the same as selecting "Add" in the UI and selecting the rectangular body as the merge scope.
Let us know if you have any other questions. Thanks for using FeatureScript!
After adjusting the syntax it worked.... Much appreciated!
Description of queries in general: https://cad.onshape.com/FsDoc/library.html#module-query.fs
qUnion specifically (what you are looking for with query + query): https://cad.onshape.com/FsDoc/library.html#qUnion-array
But I guess feature script is scripting and not coding in traditional sense but overloading + would make easier to understand.
Or a push operation if it was a list.
But never mind it works. But I guess I'll be doing alot more scripting in the future since it's truly awesome!
Something like