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.

order of iteration For loop for FACE query

theodore_peterstheodore_peters Member Posts: 15
edited February 2017 in FeatureScript
I have seen the path method for getting the correct order of edges, is there a way i can do it for faces as well?

It creates the stairs, but as you know, it will not iterate thorugh the query in any specific order.

Any suggestions?

        var allfaces is Query = qEverything(EntityType.FACE);

Comments

  • theodore_peterstheodore_peters Member Posts: 15
    I'm trying this method now, and it says qContainsPoint failed...any idea why?

            var beginningface is Query= qContainsPoint(qEverything(EntityType.FACE), vector(0,0,0));
            var nextface = beginningface;
            for (var i = 0; i < definition.staircount; i += 1)
            {
                var thisface is Query = nextface;
                opExtrude(context, id + ("extrude1"~toString(i)), {
                        "entities" : nextface,
                        "direction" : vector(0,0,1),
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : (i+1)*definition.rise
                });
                nextface=qTangentConnectedFaces(thisface);
            }

  • theodore_peterstheodore_peters Member Posts: 15
    I got it!

    
            for (var i = 0; i < definition.staircount; i += 1)
            {
                var thisface is Query = qContainsPoint(qCreatedBy(id + "mainsketch", EntityType.FACE), vector(((i)*(definition.run/inch))+0.1,0,0)*inch);
                opExtrude(context, id + ("extrude1"~toString(i)), {
                        "entities" : thisface,
                        "direction" : vector(0,0,1),
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : (i+1)*definition.rise
                });
            
               
            }

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 486
    edited February 2017
    I don't know the full code, but it's possible a cleaner way would have been to use a sketchEntityQuery, with the string id you used to originally create the entity. It would likely have slightly better performance, but mainly, it would avoid the code with manual calculation of that point for qContainsPoint (which could be hard to maintain as the feature evolves).

    (Looking again, if you're finding sketch regions, those aren't associated with individual ids, so your solution is likely the best one)

  • theodore_peterstheodore_peters Member Posts: 15
    rather than offsetting by 0.1 i should use 0 and subtract the previous face from the returned query, i was getting tired and lazy at that point. I will update it.
  • theodore_peterstheodore_peters Member Posts: 15
    edited February 2017
    or instead of creating line segments inside the major floorplan, i could create a rectangle for each step and reference that ID with sketchEntityQuery
  • theodore_peterstheodore_peters Member Posts: 15
    edited February 2017
    FYI if anyone runs into the issue where it doesnt like the vector being used for qContainsPoint, it needs to be a length vector(multiply the vector by a unit)

    the reverse is true for direction vectors, if your vector is a length vector make sure you divide by a unit
Sign In or Register to comment.