Help... do you know what wrong it is?

joseph_ho608
joseph_ho608 Member Posts: 4 ✭

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    edited August 2025

    Yes, what's wrong is that you used ChatGPT 😁

    Use the code snippets menu at the top. Also check out the learning reasources here:

    https://learn.onshape.com/learn/course/featurescript-fundamentals

    Senior Director, Technical Services, EMEA
  • joseph_ho608
    joseph_ho608 Member Posts: 4 ✭

    Not ChatGPT but Gemini, hehe😅

    I have fixed some and tried to spot out the rest but failed.

  • Matt_Shields
    Matt_Shields Member, Onshape Employees Posts: 991 PRO

    Ha, AI is not great at FS. This is valid code:

    FeatureScript 2737;
    import(path : "onshape/std/common.fs", version : "2737.0");
    
    annotation { "Feature Type Name" : "Offroad Wheel 1:12" }
    export const offroadwheel = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Wheel Diameter"}
            isLength(definition.diameter, { (millimeter) : [0, 60, 1000] } as LengthBoundSpec);
            
            annotation { "Name" : "Wheel Width", "Default" : 30 * millimeter }
            isLength(definition.width, LENGTH_BOUNDS);
    
            annotation { "Name" : "Number of Holes", "Default" : 6 }
            isInteger(definition.holes, POSITIVE_COUNT_BOUNDS);
        }
        {
            const diam = definition.diameter;
            const width = definition.width;
            const holes = definition.holes;
    
            var wheelsketch = newSketch(context, id + "wheelSketch", {
                    "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
                });
            skLineSegment(wheelsketch, "line1", {
                        "start" : vector(0, 0) * millimeter,
                        "end" : vector(0 * millimeter, width)
                    });
            skArc(wheelsketch, "arc1", {
                        "start" : vector(0 * millimeter, width),
                        "mid" : vector(diam, width),
                        "end" : vector(diam, 0 * millimeter)
                    });
    
            skSolve(wheelsketch);
        });