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.

Hello everyone, I am trying to create a feature script that let me select a plane and put a sketch

image.png

Hello everyone, I am trying to create a feature script that let me select a plane and put this sketch. This is what I have so far but it still creates an error.

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

annotation { "Feature Type Name" : "Rail Profile" }
export const railProfile = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// ----- Plane selector -----
annotation {
"Name" : "Sketch Plane",
"Filter" : EntityType.PLANE || EntityType.FACE
}
definition.plane is Query;

    // ----- Dimensions -----
    annotation { "Name" : "Vertical (0.052)" }
    isLength(definition.vert1);

    annotation { "Name" : "Offset from left (2)" }
    isLength(definition.offsetX);

    annotation { "Name" : "Drop height (4.5)" }
    isLength(definition.dropHeight);

    annotation { "Name" : "Lower vertical (1.948)" }
    isLength(definition.lowerVert);

    annotation { "Name" : "Lower horizontal (3)" }
    isLength(definition.lowerHoriz);

    annotation { "Name" : "Lower rise (1)" }
    isLength(definition.lowerRise);

    annotation { "Name" : "Bottom Offset (3.75)" }
    isLength(definition.bottomOffset);
})

{
// ================================
// Create sketch
// ================================
var sketch = newSketch(context, id + "sketch", {
"sketchPlane" : definition.plane
});

// =====================================
// Build geometry relative to origin
// =====================================

// Starting reference point (top-left corner)
const start = vector(0 * inch, 0 * inch);

// Vertical small segment
const p1 = start;
const p2 = start - vector(0, definition.vert1);

// Horizontal to the right (2 in)
const p3 = p2 + vector(definition.offsetX, 0);

// Vertical drop (4.5)
const p4 = p3 - vector(0, definition.dropHeight);

// Diagonal corner
const p5 = p4 - vector(definition.lowerHoriz, definition.lowerVert);

// Small lower vertical
const p6 = p5 - vector(0, definition.lowerRise);

// Lower horizontal
const p7 = p6 + vector(definition.lowerHoriz, 0);

// Bottom offset downward
const p8 = p7 - vector(0, definition.bottomOffset);

// =====================================
// Add line segments
// =====================================
skLineSegment(sketch, "seg1", { "start" : p1, "end" : p2 });
skLineSegment(sketch, "seg2", { "start" : p2, "end" : p3 });
skLineSegment(sketch, "seg3", { "start" : p3, "end" : p4 });
skLineSegment(sketch, "seg4", { "start" : p4, "end" : p5 });
skLineSegment(sketch, "seg5", { "start" : p5, "end" : p6 });
skLineSegment(sketch, "seg6", { "start" : p6, "end" : p7 });
skLineSegment(sketch, "seg7", { "start" : p7, "end" : p8 });

skSolve(sketch);

};

Sign In or Register to comment.