Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

wickedDesignswickedDesigns 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).

Answers

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @wickedDesigns

    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).
    Jake Rosenfeld - Modeling Team
  • wickedDesignswickedDesigns Member Posts: 6
    I was hoping there might be a way to do this without additional input from the user, some sort of query that would look for bodies which were generated by an extrude or a thicken.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,354
    @wickedDesigns outside of a feature, a body is a body regardless of how it was created.

    Senior Director, Technical Services, EMEAI
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @NeilCooke I think the issue @wickedDesigns is having is that qCapEntity takes a featureId rather than a body Query as its input.  @ilya_baran is there a way you can think of to get a list of feature ids for a certain feature type? Or even just a list of all the previous feature ids? I can't think of one.

    Jake Rosenfeld - Modeling Team
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    Jake, I cannot think of a way.  Without knowing the high-level goal, I can't say if there's a way to get around this.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • lanalana Onshape Employees Posts: 693
    I did a quick experiment passing [ANY_ID] as Id to qCapQuery(), that did not work. Not sure if I'm more disappointed or relieved: if it worked performance would've been bad.  May be  for such use cases we should implement a filter by history type .
  • leon_pootleon_poot Member, Developers Posts: 87 ✭✭✭
    edited April 2017
    @wickedDesigns If you want the caps of all the bodies created using Extrude or Thicken then maybe this might be a trick:
    • 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.
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Hmm... the loop through lastModifyingOperationIds doesn't sound very robust, since the last modifying operation isn't necessarily the one that created the face you need (even if you look at every individual face... for instance, a fillet modifies faces it didn't create and causes your check to fail).

    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).

  • leon_pootleon_poot Member, Developers Posts: 87 ✭✭✭
    @kevin_o_toole_1 it is a very unstable solution  indeed. A fillet modifies the face and qCapEntity returns only the modified face and not the original, and a split renders the cap completely unreachable. If there's no way of retrieving the history of an entity  then I'll have to live with that. 

    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 :smile:
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." - Douglas Adams, Mostly Harmless
Sign In or Register to comment.