What is wrong with my code

DoctorO9
DoctorO9 Member Posts: 2 EDU
// Feature to create the frame for combat robot
export const createCombatRobotFrame = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Width", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
        definition.width is ValueWithUnits;
        annotation { "Name" : "Length", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
        definition.length is ValueWithUnits;
        annotation { "Name" : "Height", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
        definition.height is ValueWithUnits;
    }
    {
        // Define parameters for the frame
        const width = getParameter(definition, "width");
        const length = getParameter(definition, "length");
        const height = getParameter(definition, "height");
        
        // Create sketch for the frame
        const sketchPlane = plane(normalId: qCreatedBy(makeId("Top")), pointOnPlane: vector(0,0,0) * inch);
        const sketch = newSketch(context, {
            "sketchPlane" : sketchPlane
        });
        
        // Create frame geometry
        skRectangle(sketch, "frame", {
            "firstCorner" : vector(0, 0) * meter,
            "secondCorner" : vector(width, length) * meter
        });
        
        // Extrude the sketch to create the frame
        extrude(context, id + "frameExtrude", {
            "entities" : qSketchRegion(id + "frameSketch", true),
            "direction" : vector(0, 0, height) * meter,
            "endBound" : BoundingType.BLIND,
            "endBoundLength" : height * meter
        });
    }
);

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    edited April 2024
    Where did you get this from? ChatGPT? Don't trust it, it knows nothing. The only way to do it properly is with research and effort.
    Senior Director, Technical Services, EMEA
  • jnewth_onshape
    jnewth_onshape Member, Onshape Employees Posts: 89 image
    There is a FeatureScript learning pathway (tutorial) here: https://learn.onshape.com/courses/featurescript-fundamentals

    FeatureScript is a powerful domain-specific language. It obeys programming language conventions you mostly know, but where it's different, it's quite different, particularly around working with topology and geometry. The tutorials are the place to start.

    Without sharing the doc, it's hard to see your errors (look in the FeatureScript Notices panel). At the very least, nothing exists in your sketch until you `skSolve(..)` the sketch, but this should be apparent once you start doing the tutorials.