Access to sketch elements

Andrew_74
Andrew_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_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    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.