Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Mismatched input

I tried every possible way, but my code just won't work. Please, guys, can you help me with this?

@include "partStudioApi.fs";
@include "arrayUtils.fs";

// =================================================================
// HELPER FUNCTIONS (FOR REUSABILITY ACROSS PRODUCTS)
// =================================================================

/**

  • Function: createCylindricalFiltrationBasket
  • Creates a simple cylindrical mesh basket inside a given tank volume.
  • @param context - The execution context.
  • @param id - The feature ID.
  • @param center - Center coordinates (X, Y) of the basket.
  • @param diameter - Outer diameter of the basket.
  • @param height - Height of the basket.
  • @param meshThickness - Thickness of the basket wall/base.
  • @param currentBody - The body to which the basket is added.
  • @returns The updated body , including the new basket.
    */
    function createCylindricalFiltrationBasket(context is Context, id is Id, center is Vector, diameter is Length, height is Length, meshThickness is Length, currentBody is ValueWith<<BODY>>) returns ValueWith<<BODY>>
    {
    // 1. Create the outer cylinder sketch (Base of the basket)
    var sketch = new Sketch(context, id + "basket_sketch");
    sketch.addCircle("basket_circle", center, diameter / 2);// 2. Extrude the cylinder (Solid base)
    var basketSolid = opExtrude(context, id + "basket_extrude", {
    "entities" : sketch.entities,
    "direction" : Z_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : height,
    "operation" : Operation.NEW
    });// 3. Shell the cylinder to create the basket walls
    // We remove the top face (Z+) and the internal material.
    var topFaceQuery = qFaces(isPlanar() && isOfPlane(makePlane(Z_AXIS, height)));var shelledBasket = opShell(context, id + "basket_shell", {
    "tools" : basketSolid,
    "removedFaces" : topFaceQuery,
    "thickness" : -meshThickness, // Shell inwards
    "tolerance" : 0.01 * millimeter
    });// 4. Add the basket to the current body set
    return opCombine(context, id + "basket_combine", {
    "operation" : CombineOperation.ADD,
    "tools" : [currentBody, shelledBasket]
    });
    }

// =================================================================
// PRODUCT FEATURE 1: TRAP-IT
// =================================================================

/**

  • Custom Feature: PROTECTOR_TRAPIT
  • annotation { "Name" : "Wall Thickness", "Default" : 5.0 * millimeter, "Min" : 1.0 * millimeter }
    definition.wallThickness is Length;

    annotation { "Name" : "Pipe Diameter", "Default" : 150.0 * millimeter }
    definition.pipeDiameter is Length;

    annotation { "Name" : "Inlet/Outlet Offset", "Default" : 100.0 * millimeter }
    definition.pipeOffset is Length;

    // 2. INPUT VALIDATION
    if (definition.wallThickness * 2 >= min(definition.length, definition.width, definition.height)) {
    reportFeatureFailed(context, id, "Wall thickness is too large relative to the tank size.");
    } var tankBody = opExtrude(context, id + "extrude_tank", {
    "entities" : sketch.entities,
    "direction" : Z_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : definition.height
    });

    // Use a robust query to select the top face for shelling
    var tankTopFaceQuery = qFaces(isPlanar() && isOfPlane(makePlane(Z_AXIS, definition.height)));

    var currentBody = opShell(context, id + "shell_tank", {
    "tools" : tankBody,
    "removedFaces" : tankTopFaceQuery,
    "thickness" : -definition.wallThickness,
    "tolerance" : 0.01 * millimeter
    });

    // STEP 3: CREATE INLET PIPE
    var inletPlane = makePlane(X_AXIS, -definition.length / 2);
    var inletCenter = vector(-definition.length / 2, 0 * millimeter, definition.pipeOffset);
    var inletSketch = new Sketch(context, id + "sketch_inlet", { "sketchPlane" : inletPlane });
    inletSketch.addCircle("inlet_circle", inletCenter, definition.pipeDiameter / 2);

    currentBody = opExtrude(context, id + "cut_inlet", {
    "entities" : inletSketch.entities,
    "direction" : X_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : definition.wallThickness + 20 * millimeter,
    "operation" : Operation.REMOVE,
    "bodyType" : BodyType.SOLID,
    "tools" : currentBody
    });

    currentBody = opExtrude(context, id + "stub_inlet", {
    "entities" : inletSketch.entities,
    "direction" : -X_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : definition.pipeDiameter * 0.5,
    "operation" : Operation.ADD,
    "bodyType" : BodyType.SOLID,
    "tools" : currentBody
    });

    // STEP 4: CREATE OUTLET PIPE
    var outletPlane = makePlane(X_AXIS, definition.length / 2);
    var outletCenter = vector(definition.length / 2, 0 * millimeter, definition.pipeOffset);
    var outletSketch = new Sketch(context, id + "sketch_outlet", { "sketchPlane" : outletPlane });
    outletSketch.addCircle("outlet_circle", outletCenter, definition.pipeDiameter / 2);

    currentBody = opExtrude(context, id + "cut_outlet", {
    "entities" : outletSketch.entities,
    "direction" : -X_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : definition.wallThickness + 20 * millimeter,
    "operation" : Operation.REMOVE,
    "bodyType" : BodyType.SOLID,
    "tools" : currentBody
    });

    currentBody = opExtrude(context, id + "stub_outlet", {
    "entities" : outletSketch.entities,
    "direction" : X_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : definition.pipeDiameter * 0.5,
    "operation" : Operation.ADD,
    "bodyType" : BodyType.SOLID,
    "tools" : currentBody
    });

    // STEP 5: FINAL OUTPUT
    setBodyType(context, id, { "entities" : currentBody, "bodyType" : BodyType.SOLID });}
    {
    // STEP 1 & 2: CREATE MAIN TANK BODY AND SHELL
    var sketch = new Sketch(context, id + "sketch_main");
    sketch.addRect("main_rect", center(0, 0), definition.length, definition.width, new BoundingBox(
    vector( -definition.length / 2, -definition.width / 2, 0 * millimeter),
    vector( definition.length / 2, definition.width / 2, 0 * millimeter))
    );}
    );

// =================================================================
// PRODUCT FEATURE 2: ECOPROTECTOR
// =================================================================

/**

  • Custom Feature: PROTECTOR_ECOPROTECTOR
  • Generates a configurable ECOPROTECTOR (First-Flush diverter/Screening) unit.
  • annotation { "Name" : "Wall Thickness", "Default" : 5.0 * millimeter, "Min" : 1.0 * millimeter }
    definition.wallThickness is Length;

    annotation { "Name" : "Basket Diameter", "Default" : 500.0 * millimeter }
    definition.basketDiameter is Length;

    annotation { "Name" : "Basket Height", "Default" : 600.0 * millimeter }
    definition.basketHeight is Length;

    annotation { "Name" : "Mesh Thickness", "Default" : 3.0 * millimeter }
    definition.meshThickness is Length;

    annotation { "Name" : "Pipe Diameter", "Default" : 150.0 * millimeter }
    definition.pipeDiameter is Length;

    annotation { "Name" : "Pipe Offset (Z)", "Default" : 100.0 * millimeter }
    definition.pipeOffset is Length;

    // 2. INPUT VALIDATION
    if (definition.basketDiameter > definition.tankWidth - definition.wallThickness * 2 ||
    definition.basketDiameter > definition.tankLength - definition.wallThickness * 2) {
    reportFeatureFailed(context, id, "Basket diameter is too large to fit inside the tank.");
    }
    if (definition.basketHeight > definition.tankHeight) {
    reportFeatureFailed(context, id, "Basket height exceeds tank height.");
    } var sketch = new Sketch(context, id + "sketch_main");
    sketch.addRect("main_rect", center(0, 0), definition.tankLength, definition.tankWidth, new BoundingBox(
    vector( -definition.tankLength / 2, -definition.tankWidth / 2, 0 * millimeter),
    vector( definition.tankLength / 2, definition.tankWidth / 2, 0 * millimeter))
    );

    var tankBody = opExtrude(context, id + "extrude_tank", {
    "entities" : sketch.entities,
    "direction" : Z_DIRECTION,
    "endBound" : EndBound.BLIND,
    "depth" : definition.tankHeight
    });

    // Use a robust query to select the top face for shelling
    var tankTopFaceQuery = qFaces(isPlanar() && isOfPlane(makePlane(Z_AXIS, definition.tankHeight)));

    var currentBody = opShell(context, id + "shell_tank", {
    "tools" : tankBody,
    "removedFaces" : tankTopFaceQuery,
    "thickness" : -definition.wallThickness,
    "tolerance" : 0.01 * millimeter
    });

    // =================================================================
    // STEP 3: ADD INTERNAL FILTRATION BASKET
    // =================================================================

    // The basket is centered in the tank (X=0, Y=0) and sits on the floor (Z=0).
    currentBody = createCylindricalFiltrationBasket(context, id + "eco_basket",
    vector(0 * millimeter, 0 * millimeter, 0 * millimeter),
    definition.basketDiameter,
    definition.basketHeight,
    definition.meshThickness,
    currentBody);


    // =================================================================
    // STEP 4: CREATE INLET AND OUTLET PIPES
    // (Re-using the logic from TRAP-IT, but using the new ECOPROTECTOR parameters)
    // =================================================================

    // INLET PIPE
    var inletPlane = makePlane(X_AXIS, -definition.tankLength / 2);
    var inletCenter = vector(-definition.tankLength / 2, 0 * millimeter, definition.pipeOffset);
    var inletSketch = new Sketch(context, id + "sketch_inlet", { "sketchPlane" : inletPlane });
    inletSketch.addCircle("inlet_circle", inletCenter, definition.pipeDiameter / 2);

    currentBody = opExtrude(context, id + "cut_inlet", {
    "entities" : inletSketch.entities, "direction" : X_DIRECTION, "endBound" : EndBound.BLIND,
    "depth" : definition.wallThickness + 20 * millimeter, "operation" : Operation.REMOVE,
    "bodyType" : BodyType.SOLID, "tools" : currentBody
    });
    currentBody = opExtrude(context, id + "stub_inlet", {
    "entities" : inletSketch.entities, "direction" : -X_DIRECTION, "endBound" : EndBound.BLIND,
    "depth" : definition.pipeDiameter * 0.5, "operation" : Operation.ADD,
    "bodyType" : BodyType.SOLID, "tools" : currentBody
    });

    // OUTLET PIPE
    var outletPlane = makePlane(X_AXIS, definition.tankLength / 2);
    var outletCenter = vector(definition.tankLength / 2, 0 * millimeter, definition.pipeOffset);
    var outletSketch = new Sketch(context, id + "sketch_outlet", { "sketchPlane" : outletPlane });
    outletSketch.addCircle("outlet_circle", outletCenter, definition.pipeDiameter / 2);

    currentBody = opExtrude(context, id + "cut_outlet", {
    "entities" : outletSketch.entities, "direction" : -X_DIRECTION, "endBound" : EndBound.BLIND,
    "depth" : definition.wallThickness + 20 * millimeter, "operation" : Operation.REMOVE,
    "bodyType" : BodyType.SOLID, "tools" : currentBody
    });
    currentBody = opExtrude(context, id + "stub_outlet", {
    "entities" : outletSketch.entities, "direction" : X_DIRECTION, "endBound" : EndBound.BLIND,
    "depth" : definition.pipeDiameter * 0.5, "operation" : Operation.ADD,
    "bodyType" : BodyType.SOLID, "tools" : currentBody
    });

    // =================================================================
    // STEP 5: FINAL OUTPUT
    // =================================================================
    setBodyType(context, id, { "entities" : currentBody, "bodyType" : BodyType.SOLID });}
    {
    // =================================================================
    // STEP 1 & 2: CREATE MAIN TANK BODY AND SHELL (Same as TRAP-IT)
    // =================================================================}
    );

Comments

  • Caden_ArmstrongCaden_Armstrong Member Posts: 332 PRO

    Wow that is some real AI garbage. Whats wrong?… Literally all of it. Its impressively bad, I don't see a single valid line of code.

    The unfortunate fact is that no AI can produce working featurescript.
    You'll have to do it the old fashion way and either learn it yourself or hire someone.
    I suggest the learning center - Onshape has some great FeatureScript resources.
    https://learn.onshape.com/courses/featurescript-fundamentals

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • Jacob_CorderJacob_Corder Member Posts: 139 PRO
    edited October 14

    I agree with @Caden_Armstrong, None of those functions exist at all. My chatGPT says it was generated with chatGPT 3.5 or some cheap 3.5 clone. AI is funny sometimes

  • Caden_ArmstrongCaden_Armstrong Member Posts: 332 PRO

    The real question is - what are you trying to do? If you can use configurations to solve your problem that is going to be a much simpler solution than a featurescript. Especially if all you're trying to do is generate a part with a few variables.

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
Sign In or Register to comment.