FS generated sketch to be accessible in Asseblies

MakotoNinja
MakotoNinja Member Posts: 6 EDU
Aloha All,

I am trying to write a FS that generates a sketch that is accessible from within Assemblies. What I am seeing is that a feature is generated with the sketch I have devised but this "sketch" isn't available to insert into an Assembly. Is there a way to create a sketch in FS that shows up as an actual sketch instead of a feature?
The first feature in the following image shows the sketch as generated by FS and the second feature in the list is a vanilla sketch created with the sketch button. Only the latter is available to insert into an Assembly.

I am new to FS but not new at programming. My code is as follows:
FeatureScript 1993;
import(path : "onshape/std/common.fs", version : "1993.0");

const BOUNDS = {(unitless) : [10, 100, 1e5]} as IntegerBoundSpec;

annotation { "Feature Type Name" : "Axes" }
export const axes = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
    // Define the parameters of the feature type
    annotation
    {
        "Name" : "Sketch Plane",
        "Filter" : EntityType.FACE,
        "MaxNumberOfPicks" : 1
    }
    definition.sketchPlane is Query;
    
    annotation
    {
        "Name" : "Diameter",
        "UIHint" : [UIHint.SHOW_LABEL, UIHint.REMEMBER_PREVIOUS_VALUE],
        "Description" : "Set the diameter of the circle"
    }
    // isLength(definition.radius, LENGTH_BOUNDS);
    isInteger(definition.diameter, BOUNDS);
}
{
    var diameter = definition.diameter;
    var splane = definition.sketchPlane;
    
    // Define the function's action
    var sketch1 = newSketch(context, id + "sketch1", {
        "sketchPlane" : splane
    });
    skCircle(sketch1, "circle1", {
        "center" : vector(0, 0) * millimeter,
        "radius" : (diameter / 2) * millimeter,
        "construction" : true
    });
    skLineSegment(sketch1, "line1", {
        "start" : vector(-diameter / 2, 0) * millimeter,
        "end" : vector(diameter / 2, 0) * millimeter,
        "construction" : true
    });
    skLineSegment(sketch1, "line2", {
        "start" : vector(0, diameter / 2) * millimeter,
        "end" : vector(0, -diameter / 2) * millimeter,
        "construction" : true
    });
    skSolve(sketch1);
});

Comments

  • TillysInteriors
    TillysInteriors Member Posts: 12 PRO

    I'd like this too. Is there an improvement request?

  • Scott_Boeberitz
    Scott_Boeberitz Member Posts: 14 PRO
    edited October 20

    I just checked to confirm that FS generated sketch edges can be included in composite parts. So I threw an extra few lines onto your script to wrap the sketch into a new composite part. This part can be put into an assembly.

    image.png image.png

    EDIT: forgot to add the changed code:

    FeatureScript 1993;
    import(path : "onshape/std/common.fs", version : "1993.0");
    
    const BOUNDS = {(unitless) : [10, 100, 1e5]} as IntegerBoundSpec;
    
    annotation { "Feature Type Name" : "Axes" }
    export const axes = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation
            {
                "Name" : "Sketch Plane",
                "Filter" : EntityType.FACE,
                "MaxNumberOfPicks" : 1
            }
            definition.sketchPlane is Query;
    
            annotation
            {
                "Name" : "Diameter",
                "UIHint" : [UIHint.SHOW_LABEL, UIHint.REMEMBER_PREVIOUS_VALUE],
                "Description" : "Set the diameter of the circle"
            }
            // isLength(definition.radius, LENGTH_BOUNDS);
            isInteger(definition.diameter, BOUNDS);
        }
        {
            var diameter = definition.diameter;
            var splane = definition.sketchPlane;
    
            // Define the function's action
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : splane
                });
            skCircle(sketch1, "circle1", {
                        "center" : vector(0, 0) * millimeter,
                        "radius" : (diameter / 2) * millimeter,
                        "construction" : true
                    });
            skLineSegment(sketch1, "line1", {
                        "start" : vector(-diameter / 2, 0) * millimeter,
                        "end" : vector(diameter / 2, 0) * millimeter,
                        "construction" : true
                    });
            skLineSegment(sketch1, "line2", {
                        "start" : vector(0, diameter / 2) * millimeter,
                        "end" : vector(0, -diameter / 2) * millimeter,
                        "construction" : true
                    });
            skSolve(sketch1);
    
            // Composite parts can't contain sketch bodies, so copy each sketch edge
            // into a standalone wire body first. Edges are extracted one at a time
            // because opExtractWires fails when edges cross or 3+ meet at a point
            // (the lines cross at the center and touch the circle at their ends).
            for (var entityId in ["circle1", "line1", "line2"])
            {
                opExtractWires(context, id + "wires" + entityId, {
                            "edges" : sketchEntityQuery(id + "sketch1", EntityType.EDGE, entityId)
                        });
            }
    
            opCreateCompositePart(context, id + "compositePart", {
                        "bodies" : qCreatedBy(id + "wires", EntityType.BODY),
                        "closed" : true
                    });
        });