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.

Options

how can i take the thickness value from the sheet metal

PTYPTY Member Posts: 1
I've made a copy of "CalculateBounds.fs script" and I've got a script that sets the length and width, but I can't figure out how to get the thickness out of the sheet metal.

I added function calculateFlatSMBounds to the end of the following code which sets the description field to sheet metal dimensions.


function calculateFlatSMBounds(context is Context, id is Id, definition is map)
{
    const flatFace = definition.face;

    const flatFaces = qTangentConnectedFaces(flatFace);
    // We use evPlane here because it is what newSketch uses
    const flatFacePlane = evPlane(context, {
                "face" : flatFace
            });

    const points = getBoxPoints(context, flatFaces, [], flatFacePlane, definition.edgeSamples);

    var boundingBox;

    if (definition.calculateSmallest)
        boundingBox = calculateMinBox(context, flatFaces, [], flatFacePlane, definition.edgeSamples);

    else
    {
        var boxXDirection;
        if (definition.defaultCSys)
            boxXDirection = X_DIRECTION;
        else
        {
            if (size(evaluateQuery(context, definition.alignEdge)) != 2)
                throw regenError("Please select two points to align the bounds", ["alignEdge"]);

            else
            {
                const boxXPoints = qUnion([qSheetMetalFlatFilter(definition.alignEdge, SMFlatType.YES), qCorrespondingInFlat(definition.alignEdge)]);
                boxXDirection = evVertexPoint(context, {
                                "vertex" : qNthElement(boxXPoints, 0)
                            }) - evVertexPoint(context, {
                                "vertex" : qNthElement(boxXPoints, 1)
                            });
            }
        }
        const angle = atan2(boxXDirection[1], boxXDirection[0]) % (PI / 2 * radian);
        boundingBox = getBox2D(points, angle);
    }

    const box3dCSys = coordSystem(WORLD_ORIGIN, vector(cos(boundingBox.angle), sin(boundingBox.angle), 0), Z_DIRECTION);

    const box3d = evBox3d(context, {
                "topology" : flatFaces,
                "tight" : true,
                "cSys" : box3dCSys
            });

    const boxPoints = [
            box3d.minCorner,
            vector(box3d.minCorner[0], box3d.maxCorner[1], 0 * meter),
            box3d.maxCorner,
            vector(box3d.maxCorner[0], box3d.minCorner[1], 0 * meter)
        ];

    var sketchBoxPoints = mapArray(boxPoints, function(point)
    {
        return worldToPlane(flatFacePlane, toWorld(box3dCSys, point));
    });

    sketchBoxPoints = append(sketchBoxPoints, sketchBoxPoints[0]);

    const sketch = newSketch(context, id + "sketch", {
                "sketchPlane" : flatFace
            });

    skPolyline(sketch, "polyline", {
                "points" : sketchBoxPoints,
                "construction" : true
            });

    skSolve(sketch);

    if (definition.featureResult == BoundsFeatureResult.PRINT)
    {
        // Print the result to the FS Console
        const unitInfo = getUnitAndUnitString(definition.unitOutput);
        const extents = getExtents(boundingBox, 0, unitInfo.lengthUnit);
        const length = extents.width;
        const width = extents.height;
       

        //My code, which sets the description field for the sheet metal part dimensions
        setProperty(context, {
                "entities" : definition.bodies,
                "propertyType" : PropertyType.DESCRIPTION,
                "value" : "Plate PL? x "~ length ~ " x " ~ width
        });



        setErrorEntities(context, id, {
                    "entities" : qCreatedBy(id + "sketch", EntityType.EDGE)
                });
        opDeleteBodies(context, id + "deleteSketch", {
                    "entities" : qCreatedBy(id + "sketch")
                });
    }
}

Sign In or Register to comment.