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.

sheet metal selecting vertices issues?

Hi,

I'm trying to add some holes at selected vertexes on my flat sheet metal build but for some reason I can't pull the coordinates from the vertex's which is causing issues.

Anyone got any ideas on how i get the vertices locations to add to a sketch which is on my flat panel?

Code below keeps telling me the points are strings and when i print them they show as undefined…
FeatureScript 2491;
import(path : "onshape/std/common.fs", version : "2491.0");

annotation {"Feature Type Name": "Bend Indicators"}
export const mySimpleInputFeature = defineFeature(function(context is Context, id is Id, definition is map)
{
precondition
{
// Allow the user to select a face from the flat pattern
annotation { "Name" : "Select Flat Pattern Face", "Filter" : EntityType.FACE && AllowFlattenedGeometry.YES, "MaxNumberOfPicks" : 1 }
definition.selectedFace is Query;

    // Allow the user to select multiple points on the flat pattern for drawing circles
    annotation { "Name" : "Select Points for Circles", "Filter" : EntityType.VERTEX && AllowFlattenedGeometry.YES, "MaxNumberOfPicks" : undefined }
    definition.selectedPoints is Query;
}
{
    // Ensure a face is selected
    if (isQueryEmpty(context, definition.selectedFace)) {
        throw regenError("You must select a face.");
    }

    // Ensure points are selected
    if (isQueryEmpty(context, definition.selectedPoints)) {
        throw regenError("You must select points where the circles will be drawn.");
    }

    // Query debug: Ensure we are selecting flat pattern geometry correctly
    println("Selected flat pattern face: " ~ definition.selectedFace);

    // Get vertices from the flat pattern context (the points you selected)
    var flatPatternVertices = evaluateQuery(context, definition.selectedPoints);
    println("Number of vertices in flat pattern: " ~ size(flatPatternVertices));
    
    // Check if there are vertices
    if (size(flatPatternVertices) == 0) {
        throw regenError("No vertices found in the flat pattern.");
    }

    // Use the selected face as the sketch plane
    var face = definition.selectedFace;

    // Create a sketch directly on the selected face
    var holeSketch = newSketch(context, id + "holeSketch", {
        "sketchPlane": face  // Directly use the selected face as the sketch plane
    });

    // Iterate over the selected points and add 3mm diameter circles at each point
    for (var i = 0; i < size(flatPatternVertices); i += 1)
    {
        // Use the vertex point directly to create a circle
        var vertexPosition = evVertexPoint(context, { "vertex": flatPatternVertices[i] }).position;
        println("Vertex " ~ i ~ " position: " ~ vertexPosition);

        // Add a 3mm diameter circle at each vertex
        skCircle(holeSketch, "circle" ~ i, {
            "center": worldToPlane(face, vertexPosition),  // Project 3D point to 2D plane
            "radius": 1.5 * millimeter  // Radius = 1.5mm for a 3mm diameter circle
        });
    }

    // Solve the sketch
    skSolve(holeSketch);
}

});

Sign In or Register to comment.