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.

Trouble selecting shapes,edges using query/filters

fredrik_tärnellfredrik_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:
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:

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,651
    That's because an inner loop is still a face. Have you tried this?

    qSketchRegion (featureId is Id, filterInnerLoops is boolean) returns Query

    A query for all fully enclosed, 2D regions created by a sketch.

    ParameterTypeAdditional Info
    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.

    Senior Director, Technical Services, EMEAI
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    did you tried qSketchRegion(id, "filterInnerLoops": true) ?

  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Thanks for quick turnaround :-)

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



     

  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Can I build an array of inner circle id's and pass it to the opExtrude some how?

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited June 2017
    do you really need all this circles in one sketch? maybe better create several sketches each containing only geometry you want to extrude
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Well tried that just now. But I run into the same issue at this stage. 
    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?
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    And.. If I do the circles in multiple sketches it does not give me the option to create the "collars" i'm looking for.
    The yellow part I highlighted in the previous screenshot


  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited June 2017
    i don't really understand what result you want to obtain from those concentric circles. you need a plate with a number of holes, and a collar in each hole, created in place by FS? if it is so you need to create rectangular profile and a number of outer holes in sketch1, extrude it, then create a number of inner and outer circles in sketch2 and extrude it again, all extrudes with filterInnerLoops=true
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    This is what I'm trying to accomplish with the featurescript 


  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    So Im trying to learn how to best select the faces I want. Really should be possible with a single sketch and both my inner and outer circles. Making a first extrude using the rectangle and the inner cicles blindly in one direction and then a second extrude opposite direction and only using the faces created inbetween the inner and outer circle.
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Two sketches seems like by far the simplest solution.

    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!

  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Updated as you suggested Kevin looks much better. Thanks Kevin and other for the quick support!
    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.

     
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Merging them .... regenerates ok but still as separate solids.. A total of 9 parts.
    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..

            var target = qCreatedBy(id + "extrude1", EntityType.BODY);
            var tools = qCreatedBy(id + "extrude2", EntityType.BODY);
            debug(context, tools); // debug: Query resolves to 8 bodies
            opBoolean(context, id + "boolean1", {
                    "tools" : tools,
                    "targets" : target,
                    "operationType" : BooleanOperationType.UNION
            });

    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?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    if boolean operation type is union then you need only tools - use "tools" : qUnion(tools,target)

  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    edited June 2017
    Would be nice if + was overloaded for the map type.

    <div>var target = qCreatedBy(id + "extrude1", EntityType.BODY); 
    </div><div>var tools = qCreatedBy(id + "extrude2", EntityType.BODY); 
    <span style="background-color: transparent; color: inherit; font-size: inherit; font-family: Flama, sans-serif;">var merge = target + tools;</span>
    </div>


    But this generates :
    &nbsp;Can not add Query (map) and Query (map)<br>


  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Or if I could do
    var tools = qEverything(EntityType.SOLID);

    Since:

    <p></p><p>var tools = qEverything(EntityType.BODY);</p>

    returns 90 bodies which are not all solids (or maybe none are??)

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @fredrik_tärnell

    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!

    Jake Rosenfeld - Modeling Team
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    edited June 2017
    if boolean operation type is union then you need only tools - use "tools" : qUnion(tools,target)

    Thanks Konstantin,

    After adjusting the syntax it worked.... Much appreciated!

    <div>var target = qCreatedBy(id + "extrude1", EntityType.BODY);
    <span style="background-color: transparent; color: inherit; font-size: inherit; font-family: Flama, sans-serif;">var tools = qCreatedBy(id + "extrude2", EntityType.BODY);
    </span>
    </div><div>var merge = qUnion([tools,target]);</div>
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    A couple additional resources for you:
    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 
    Jake Rosenfeld - Modeling Team
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Thanks @Jake_Rosenfeld! Will try to read-up
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    @Jake_Rosenfeld
    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!
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    edited June 2017
    I don't like overloading + for something that is not really addition, but you can.
    Something like
    operator+(q1 is Query, q2 is Query) returns Query
    {
        return qUnion([q1, q2]);
    }
    
    Be sure to remember to export if using across modules.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • fredrik_tärnellfredrik_tärnell Member Posts: 29 ✭✭
    Super @ilya_baran!
Sign In or Register to comment.