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.

Joining Tabs/Tags on Frames

aaron_harris672aaron_harris672 Member Posts: 4 PRO

Hi,

Can anyone help me with trying to set up a feature script so that I can easily add in joining tab/tags to frames using either box section or angle. i have tried with the following code but keep getting errors.

FeatureScript 1640; // Specify the FeatureScript version

// Feature definition
annotation { "Feature Type Name": "Joining Tab" }
export const joiningTab = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// Tab width as a length input
annotation { "Name": "Tab Width", "UIHint": "DISTANCE" }
definition.tabWidth is length;

    // Tab height as a length input
    annotation { "Name": "Tab Height", "UIHint": "DISTANCE" }
    definition.tabHeight is length;

    // Tab spacing as a length input
    annotation { "Name": "Tab Spacing", "UIHint": "DISTANCE" }
    definition.tabSpacing is length;

    // Joining part input (should be a body or face)
    annotation { "Name": "Joining Part" }
    definition.joiningPart is Query;
}
{
    // Fetch the selected edges for tab creation
    const edges = evaluateQuery(context, definition.edges);

    // Loop through the edges and create tabs
    for (var edge in edges)
    {
        // Extract the tangent line from the edge
        const edgeCurve = evEdgeTangentLine(context, { "edge": edge });
        const edgeLength = evLength(context, { "entities": edge });

        // Create tabs along the edge at intervals
        for (var pos = 0; pos < edgeLength; pos += definition.tabSpacing)
        {
            const tabOrigin = edgeCurve.origin + edgeCurve.direction * pos;

            // Define the tab plane for extrusion
            const tabPlane = plane(tabOrigin, edgeCurve.direction, vector(0, 0, 1));

            // Create the tab's sketch
            const tabSketch = planarSketch(context, id + "tabSketch" ~ pos, {
                "plane": tabPlane
            }, function(sketchContext) {
                // Draw a rectangle to represent the tab
                skRectangle(sketchContext, "tabRect", {
                    "corner1": vector(0, 0) - vector(definition.tabWidth / 2, 0),
                    "corner2": vector(0, definition.tabHeight) + vector(definition.tabWidth / 2, 0)
                });
            });

            // Extrude the tab from the sketch
            const tabExtrude = opExtrude(context, id + "tabExtrude" ~ pos, {
                "entities": qSketchRegion(id + "tabSketch" ~ pos),
                "direction": edgeCurve.direction,
                "operationType": NewBodyOperationType.ADD,
                "depth": definition.tabHeight
            });

            // Subtract the tab from the joining part
            opBoolean(context, id + "tabCutout" ~ pos, {
                "tools": qCreatedBy(tabExtrude, EntityType.BODY),
                "targets": definition.joiningPart,
                "operationType": BooleanOperationType.SUBTRACT
            });
        }
    }
}

);

Comments

Sign In or Register to comment.