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.

Problem using opExtrude in functions

frank_halmafrank_halma Member, Developers Posts: 2
I am trying to make some functions for creating extrusions. Unfortunately I cannot get things work.
When I use only 1 function, it works prefectly. Also when I disable the opExtrude, the sketches are made as I expected.

When I don't use functions I don't have any problems.

I am pretty new in FeatureScript, so probably I miss something easy...

Below the (simplified) script I tried.

Thanks a lot for helping me out!

Frank



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

const __BOOLEAN = "boolean";
const __DELETE = "delete";
const __EXTRUDE = "extrude";
const __PLANE = "plane";
const __POLYLINE = "polyline";
const __RECTANGLE = "rectangle";
const __REVOLVE = "revolve";
const __SKETCH = "sketch";

const __ZEROMM = 0 * millimeter;


annotation { "Feature Type Name" : "PARO002" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        // Define the parameters of the feature type
    }
    {
        var XMax = 300 * millimeter;
        var YMax = 200 * millimeter;
        var ZMax = 100 * millimeter;

        var index = 0;

        // Disable MB = makes CC = work
        var MB = createMainBody(context, id, index, XMax, YMax, ZMax);

        index = index + 1;

        // Disanle CC = makes MB = work
        var CC = createCutOut(context, id, index, XMax, YMax, ZMax, 2, 0 * millimeter, 0 * millimeter, 30 * millimeter, 20 * millimeter, 0.75 * YMax);

        index = index + 1;

    });


function createsketchPlane(context is Context, XMax, YMax, ZMax is ValueWithUnits, Face is number)
{
    if (Face == 1)
    {
        return plane(vector(__ZEROMM, __ZEROMM, ZMax), vector(0, 0, 1), vector(1, 0, 0));
    }
    if (Face == 2)
    {
        return plane(vector(__ZEROMM, __ZEROMM, ZMax), vector(0, -1, 0), vector(1, 0, 0));
    }
}


function createMainBody(context is Context, id is Id, index is number, XMax, YMax, ZMax is ValueWithUnits)
{
    var sketchID = getID(id, __SKETCH, index);
    var extrudeID = getID(id, __EXTRUDE, index);
    var sketchplane = createsketchPlane(context, XMax, YMax, ZMax, 1);

    var sketch = newSketchOnPlane(context, sketchID, {
            "sketchPlane" : sketchplane
        });

    skRectangle(sketch, getID(__RECTANGLE, index), {
                "firstCorner" : vector(0, 0) * millimeter,
                "secondCorner" : vector(XMax, YMax)
            });

    skSolve(sketch);

    // Without extrude sketches are made
    opExtrude(context, extrudeID, {
                "entities" : qSketchRegion(sketchID),
                "direction" : sketchplane.normal * -1,
                "endBound" : BoundingType.BLIND,
                "endDepth" : ZMax
            });

    return qCreatedBy(extrudeID, EntityType.BODY);
}

function createCutOut(context is Context, id is Id, index is number, XMax, YMax, ZMax is ValueWithUnits, Face is number, XPos, YPos, Width, Height, Depth is ValueWithUnits)
{
    var sketchID = getID(id, __SKETCH, index);
    var extrudeID = getID(id, __EXTRUDE, index);

    var sketchplane = createsketchPlane(context, XMax, YMax, ZMax, Face);

    var sketch = newSketchOnPlane(context, sketchID, {
            "sketchPlane" : sketchplane
        });

    skRectangle(sketch, getID(__RECTANGLE, index), {
                "firstCorner" : vector(-XPos, -YPos),
                "secondCorner" : vector(Width, Height)
            });

    skSolve(sketch);

    // Without extrude sketches are made
    opExtrude(context, extrudeID, {
                "entities" : qSketchRegion(sketchID),
                "direction" : sketchplane.normal * -1,
                "endBound" : BoundingType.BLIND,
                "endDepth" : Depth
            });

    return qCreatedBy(extrudeID, EntityType.BODY);
}

function getID(id is Id, name is string, index is number)
{
    return id + name + index;
}

function getID(name is string, index is number)
{
    return name ~ index;
}


Best Answer

Answers

  • frank_halmafrank_halma Member, Developers Posts: 2
    Thanks Kevin!
    I changed the getID() function, that solves it (your link was very helpful).
    I keep your PS in mind in case I have other questions.

Sign In or Register to comment.