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.

Custom Feature: Query Variable+

Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO
edited October 28 in FeatureScript

-Link to feature up front-
Query Variable has been a game changer for more programmatic workflows that save me from needing to develop custom scripts when I can instead pass other existing features through a QV and get results that way. That being said, there are some more powerful querying techniques which haven't yet been added to the default Query Variable implementation that I'm taking some time to write into an extended toolset. For example: just about everything in the old Query Explorer feature could be used as a QV to enable more parametric workflows involving spatial, geometric, or directional filtering of your queries. My long term goal is to implement all of these Query Explorer features into the new Query Variable feature but I'm starting out small with a few easier lift features and will add more over time.

The first two features in my Query Variable+ implementation are the following:
Tangent(ish) Faces

This one is simple, the qTangentConnectedFaces() function in the standard library already has an overload which allows you to specify an angle tolerance for some flexibility in the definition of the word "tangent" so I just replaced the version in Query Variable with this angular tolerance version. This lets me flood select face groups from cursed not-mesh import geometry and use the selections to create patch faces and create new clean parametric surfaces without having a feature tree to work with.

image.png

This is not a mesh.

image.png

But with a little bit of curve approximation and resurfacing later it can become usable geometry again. Selecting groups of nearly tangent faces made this much easier to execute.

Matching Bodies
Query Variable comes with the ability to select matching edges or matching faces, why not matching bodies? Well the qMatching feature doesn't allow this selection type so that's why it's not allowed here, but there's a similar function called clusterBodies that does something close to this for cut list purposes. I leveraged this into a qMatchingBodies function that allows you to select a part and the function will return all parts in the studio that clusterBodies identifies as a geometric match for the input. (With some tolerance)

image.png

Useful for workflows where you're working with repetitive geometry that's not necessarily the result of a pattern, or if you've willfully ignored the "best practices" instructions of assembly modeling workflows and need to check that your parts actually are still copies of each other at the end of the tree.

Other features I'd like to implement into the list from Query Explorer:
- Geometry filters for face types
- Distance filters
- Direction filters
- Attribute filters for sheet metal and frames
- Cap entity filters
- …And more things I'm sure will be useful to someone at some point that I have yet to discover

Comments

  • EvanReeseEvanReese Member, Mentor Posts: 2,670 PRO

    YES! I'm glad you're taking this on. It needs to be a thing.

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO
    edited October 23

    qAdjacent functionality added. Kinda wild that this one wasn't in the original Query Variable implementation actually.

    image.png

    If you look closely there's the seeds of another useful featurescript in here too.

  • S1monS1mon Member Posts: 3,733 PRO

    If you look closely there's the seeds of another useful featurescript in here too.

    Hmm. The Median curves? I had no idea there was functionality for that in Parasolid.

    Simon Gatrall | Product Development Specialist | Open For Work

  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO
    edited October 23

    There isn't, as far as I know. That tab is an extrude with an 89 degree draft, a query variable to grab all the edges of that operation and another one to subtract all edges adjacent to the first input face, and a projection of the remainder onto the input face. It's one of a few methods of medial axis approach and is somehow way more performant than the delaunay method I was working on before. Could use some size comparison threshold filtering though, which will be one of the things I add to QV+. Could turn into its own script when the concept is proven, and actually a lot of use cases for QV+ could be turned into dedicated scripts based on concept studios like this one.

  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO

    qGeometry support added. Now you can filter by all the things that qGeometry lets you filter by and use them as an input in future operations. Edge filtering for straight lines vs arcs vs other curves could have some utility for frames features. Face filters have some less obvious use cases but I could see them being handy for working with stubborn import geometry.

    image.png

    If you're following along with these additions and have suggestions on which query functions to tackle next let me know and I'll slot them into a future update. Probably next is gonna be fillets and direction queries.

  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO

    Hi Derek,

    I've had needs for qCapEntities before, so that'll be very useful!

    Jelte

  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO
    edited November 7

    Hi @Derek_Van_Allen_BD :

    I was in need of the qCapEntities Filter and created it myself as an additional option filter to "Is Created By"

    feel free to add it to your query variable+ to prevent clutter. I'd rather contribute to your good query variable + version, then create a whole bunch of new ones…

    Just ctrl-F for: "//added by for Cap Filter by Jelte" … "//end added by Jelte" and copy paste those bits. (after a bit of review and checking perhaps):

    https://cad.onshape.com/documents/d235b229e9002129febbb90e/w/4681d88c2fa02968068670d3/e/4243c76ef0022c2f4089c1f7?renderMode=0&uiState=690ddcf38ff2a03fae52d925

    There was an error displaying this embed.

  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO
    edited November 10

    AND then I went for a walk and realised a better way to implement it that's more compliant to the original Query Variables UI. So please disregard v1 and use V4 wich requires 11 small code changes/additions…

  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO

    I've also added a "Parallelish" query in my new version V6. It's a tolerant parallel query that allows a set angle tolerance. Comes in handy to filter for edges with some draft on them.

  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO

    some additional feedback @Derek_Van_Allen_BD:

    I used your query Variable + in qAdjancy mode. I wanted to query a face AND all its adjacent faces. I think this is a common use for it. However the qAdjacent only queries the adjacents, and omits the seed faces. I had to add those by uniting with an additional query. It works, but it cumbersome and less robust. if i want to edit the seed faces, i'll have to edit them in two different places.

    a simple boolean in the UI predicate would be nice:

    annotation { "Name" : "Include seeds", "Default" : true }
    definition.includeSeeds is boolean;

    and a subsequent conditional qUnion in the function.

  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO

    Dang, you've been busy. Nice implementation of nearly parallel edges, I could see that being useful for putting fillets in the XY coordinates on 3d printed parts and not on the top or bottom where they'd look terrible and mess with printability.

    I did develop the qAdjacent filter with the exact opposite case in mind where I wanted to query everything around the seed and exclude the seed on purpose to support draft features, but I could see some use cases where you might want to include the seed as well. I'll get to work on plugging these edits into the main feature.

  • EvanReeseEvanReese Member, Mentor Posts: 2,670 PRO

    On the topic of parallelish edges, I'm running into challenges where I'd like to choose ALL parallel edges in a part studio, not just limited to ones on the selected entity. I'd later use that to intersect some other criteria to get the selection count under control. I also keep wanting to be able to choose a direction in addition to any line. I very frequently want all "up" edges, and would rather pick the top plane than a random edge somewhere.

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO
    edited December 2

    Pushed an update to merge recent changes from the last few updates to the standard library's QV to keep the plus version sync'd up. Next I'll work in integrating @jelte_steur_info's cap filter and parallelish query

  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO

    qCapEntities support added. Thanks for putting in the work Jelte.

    image.png
  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO
    edited December 2

    @Derek_Van_Allen_BD : Thank you for integrating it so everybody can benefit from a great QV+ feature.

    I expect to use the parallelish a lot to fillet edges of injection molded parts after implementing drafts already. any tranverse fillets will then propagate easily accross the tangent edges…

    @EvanReese my parallelish implementation uses the queryFilterCompound.Allows_direction filter so any direction will work. And it works on multiple parts as well.

    image.png
  • jelte_steur_infojelte_steur_info Member Posts: 582 PRO

    @Derek_Van_Allen_BD

    I was just thinking about updating the qCapEntities to include a NonCap type next to End/Start/Either, only to find you already made a separate nonCapEntities query! Awesome work! you implementation is probably cleaner as well.

    This catch may also be added to qCapEntities I guess?:


    if (definition.entityType == EntityType.BODY)

    {

        throw regenError("Non-cap queries cannot resolve bodies.", ["entityType"]);
    }
    
  • Derek_Van_Allen_BDDerek_Van_Allen_BD Member Posts: 372 PRO

    Yeah I was pondering adding filters at the input level for the entity types to only allow you to select valid types for a given query but that would mean I'd need to split up the input field into several depending on what's valid for a given operation.

    I did start with cap vs noncap being a separate field but because Onshape's standard library has them defined as separate features I did them as separate selections for consistency with how you would actually implement things in a featurescript and with the Query Explorer's implementation.

Sign In or Register to comment.