future script help - beginner

rlbrk
rlbrk Member Posts: 31 ✭
I asked Chat gpt to generate me a future script code for a gridfinity bin. 
I tried to import the code and I got errors. I watched some tutorials on how to use it but I didn't manage to make it work.
how should I paste it correctly?
here is the code: 

FeatureScript 1200;
import(path : "onshape/std/geometry.fs", version : "1200.0");

annotation { "Feature Type Name" : "Gridfinity Bin" }
export const gridfinityBin = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Width", "Default" : 42 * millimeter }
        definition.width is Length;
        
        annotation { "Name" : "Depth", "Default" : 42 * millimeter }
        definition.depth is Length;
        
        annotation { "Name" : "Height", "Default" : 7 * millimeter }
        definition.height is Length;
        
        annotation { "Name" : "Wall Thickness", "Default" : 2 * millimeter }
        definition.wallThickness is Length;
    }
    {
        // Main body of the bin
        var binProfile = rectangleSketch(context, id + "binProfile", {
            "cornerA" : vector(0, 0) * millimeter,
            "cornerB" : vector(definition.width, definition.depth)
        });

        var binBody = extrude(context, id + "binBody", {
            "entities" : qSketchRegion(id + "binProfile"),
            "direction" : evOwnerSketchPlane(context, {
                "entity" : qSketchRegion(id + "binProfile")
            }).normal,
            "endBound" : BoundingType.BLIND,
            "endDepth" : definition.height
        });

        // Hollow out the bin
        var hollowProfile = rectangleSketch(context, id + "hollowProfile", {
            "cornerA" : vector(definition.wallThickness, definition.wallThickness),
            "cornerB" : vector(definition.width - definition.wallThickness, definition.depth - definition.wallThickness)
        });

        var hollowBody = extrude(context, id + "hollowBody", {
            "entities" : qSketchRegion(id + "hollowProfile"),
            "direction" : evOwnerSketchPlane(context, {
                "entity" : qSketchRegion(id + "hollowProfile")
            }).normal,
            "endBound" : BoundingType.BLIND,
            "endDepth" : definition.height - definition.wallThickness,
            "operationType" : NewBodyOperationType.REMOVE
        });

        // Create bottom cutouts
        var cutoutDiameter = 8 * millimeter;
        var cutoutRadius = cutoutDiameter / 2;
        var cutoutSpacing = 10 * millimeter;
        var cutoutPositions = [];
        for (var x = cutoutRadius; x < definition.width; x += cutoutSpacing) {
            for (var y = cutoutRadius; y < definition.depth; y += cutoutSpacing) {
                append(cutoutPositions, vector(x, y));
            }
        }

        for (var cutoutPosition in cutoutPositions) {
            var cutoutSketch = circleSketch(context, id + "cutoutSketch" + cutoutPosition, {
                "center" : cutoutPosition,
                "radius" : cutoutRadius
            });

            var cutoutExtrude = extrude(context, id + "cutoutExtrude" + cutoutPosition, {
                "entities" : qSketchRegion(id + "cutoutSketch" + cutoutPosition),
                "direction" : evOwnerSketchPlane(context, {
                    "entity" : qSketchRegion(id + "cutoutSketch" + cutoutPosition)
                }).normal,
                "endBound" : BoundingType.BLIND,
                "endDepth" : definition.wallThickness,
                "operationType" : NewBodyOperationType.REMOVE
            });
        }
    });

function rectangleSketch(context is Context, id is Id, corners is map)
{
    var sketch = newSketch(context, id, {
        "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
    });
    skRectangle(sketch, "rectangle", {
        "cornerA" : corners.cornerA,
        "cornerB" : corners.cornerB
    });
    skSolve(sketch);
    return sketch;
}

function circleSketch(context is Context, id is Id, parameters is map)
{
    var sketch = newSketch(context, id, {
        "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
    });
    skCircle(sketch, "circle", {
        "center" : parameters.center,
        "radius" : parameters.radius
    });
    skSolve(sketch);
    return sketch;
}


Comments