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.

Access to sketch elements

Andrew_74Andrew_74 Member Posts: 4
I'm probably missing something, but it seems to be unnecessarily difficult to access newly created sketch elements. 
I want to create a sketch containing two lines and then extrude one of the lines depending on other conditions. 

The extrude requires a query as input, but I can't find a query that will return an element with a specific name from a sketch. 

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 438
    Every time you create a sketch entity, you give it a sketch id (a string like "line1") which can be used to track that entity. The query which gets a particular sketch entity is named sketchEntityQuery. Used for your case:
    annotation { "Feature Type Name" : "Extrude lines" }
    export const extrudeLines = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Use other line" }
            definition.useOtherLine is boolean;
        }
        {
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
            });
            skLineSegment(sketch1, "line1", {
                    "start" : vector(0, 0) * inch,
                    "end" : vector(1, 1) * inch
            });
            skLineSegment(sketch1, "line2", {
                    "start" : vector(-1, 0) * inch,
                    "end" : vector(0, 1) * inch
            });
            skSolve(sketch1);
    
            // debug(context, sketchEntityQuery(id + "sketch1", EntityType.EDGE, "line1"));
            // debug(context, sketchEntityQuery(id + "sketch1", EntityType.EDGE, "line2"));
    
            opExtrude(context, id + "extrude1", {
                    "entities" : sketchEntityQuery(id + "sketch1", EntityType.EDGE, "line1"),
                    "direction" : vector(0, 0, 1),
                    "endBound" : BoundingType.BLIND,
                    "endDepth" : 1 * inch
            });
        });
    

    So the simple case is indeed simple.

    HOWEVER, in practice, this works well for sketch edges and points, but not for sketch regions. Regions, unlike edges, don't have convenient ids (imagine 3 rectangles creating up to 7 regions... how would you identify them?).

    So, I think most of the time, FS best practice is to use multiple sketches, so that a downstream feature (like extrude) can simply use a full sketch without worrying about the details.
Sign In or Register to comment.