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.
Using qCapEntity with a manually generated body
wickedDesigns
Member Posts: 6 ✭
Hi. I am very new to both Onshape and FeatureScript, and I'm hoping I may be missing something obvious here.
Is there a way to use qCapEntity to locate the cap of a body which was generated via an Extrude or Thicken in the PartStudio? All the examples I can find use a body generated within the FeatureScript (and thus with an easily accessible id).
Is there a way to use qCapEntity to locate the cap of a body which was generated via an Extrude or Thicken in the PartStudio? All the examples I can find use a body generated within the FeatureScript (and thus with an easily accessible id).
Tagged:
0
Answers
Glad you're interested in using FeatureScript! I've put together an example for you:
https://cad.onshape.com/documents/2bb4fa9d4317eec5da349d7d/w/9c24a855848fba9c81f10475/e/92e65b491b1834951eaf6875
Here I have the user select what features they want the cap entities for, then use their selections as input to the qCapEntity function.
(If you copy this and edit the "Select Cap 1" feature you will see that while you are editing the start caps of the selected features are colored in red. This is what the "debug()" function does when given a Query as input).
- Query all solid bodies
- Get each Id using lastModifyingOperationId
- filter for "opExtrude" or "opThicken" (probably unnecessary, but nice if you're only looking for Extrudes for example)
- qCapEntity for each of the remaining Ids
I am unsure what lastModifyingOperationId really means. Would any modifying operations on the bodies remove "opExtrude" from the Id? Which?I fiddled a bit with @Jake_Rosenfeld's public doc:
https://cad.onshape.com/documents/58e692ed8e969a0ff3ab5e1a/v/6a8ca8beb8169223a890aa94/e/b4d2b51eab9f450e66bc523d
Also, perhaps a somewhat stupid question: is there anything like Array.contains() or Array.indexOf() in FeatureScript? Can't seem to find it.
In general: There isn't a lot in FeatureScript/Onshape that gives access to state from other features (explicitly set attributes and variables are the notable exceptions). I don't see a way for you to get all faces that were created as extrude caps, but I also question whether that's the right filter to have. If your feature depends on history like that, it will behave differently for identical geometry created a different way, or for derived parts, or for parts imported from other CAD systems.
If you're able to use non-historical queries (like, say, qParallelPlanes) to do the job, awesome. If not, the right solution might just be to just have the user input the face as a parameter to your feature.
@leon_poot for contains you can use isIn. Looks like there's nothing in std for indexOf. Seems like it'd be a reasonable addition on our end (but in the mean time writing your own would just be a simple for loop with a == check).
Thanks for the tip, I knew there had to be something like it. Of course a simple loop is easily written, but those small things are save time, code and frustration