Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
future script help - beginner
harel_barak952
Member Posts: 18 ✭
I asked Chat gpt to generate me a future script code for a gridfinity bin.
I tried to import the code and I got errors. I watched some tutorials on how to use it but I didn't manage to make it work.
how should I paste it correctly?
here is the code:
I tried to import the code and I got errors. I watched some tutorials on how to use it but I didn't manage to make it work.
how should I paste it correctly?
here is the code:
FeatureScript 1200;
import(path : "onshape/std/geometry.fs", version : "1200.0");
annotation { "Feature Type Name" : "Gridfinity Bin" }
export const gridfinityBin = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Width", "Default" : 42 * millimeter }
definition.width is Length;
annotation { "Name" : "Depth", "Default" : 42 * millimeter }
definition.depth is Length;
annotation { "Name" : "Height", "Default" : 7 * millimeter }
definition.height is Length;
annotation { "Name" : "Wall Thickness", "Default" : 2 * millimeter }
definition.wallThickness is Length;
}
{
// Main body of the bin
var binProfile = rectangleSketch(context, id + "binProfile", {
"cornerA" : vector(0, 0) * millimeter,
"cornerB" : vector(definition.width, definition.depth)
});
var binBody = extrude(context, id + "binBody", {
"entities" : qSketchRegion(id + "binProfile"),
"direction" : evOwnerSketchPlane(context, {
"entity" : qSketchRegion(id + "binProfile")
}).normal,
"endBound" : BoundingType.BLIND,
"endDepth" : definition.height
});
// Hollow out the bin
var hollowProfile = rectangleSketch(context, id + "hollowProfile", {
"cornerA" : vector(definition.wallThickness, definition.wallThickness),
"cornerB" : vector(definition.width - definition.wallThickness, definition.depth - definition.wallThickness)
});
var hollowBody = extrude(context, id + "hollowBody", {
"entities" : qSketchRegion(id + "hollowProfile"),
"direction" : evOwnerSketchPlane(context, {
"entity" : qSketchRegion(id + "hollowProfile")
}).normal,
"endBound" : BoundingType.BLIND,
"endDepth" : definition.height - definition.wallThickness,
"operationType" : NewBodyOperationType.REMOVE
});
// Create bottom cutouts
var cutoutDiameter = 8 * millimeter;
var cutoutRadius = cutoutDiameter / 2;
var cutoutSpacing = 10 * millimeter;
var cutoutPositions = [];
for (var x = cutoutRadius; x < definition.width; x += cutoutSpacing) {
for (var y = cutoutRadius; y < definition.depth; y += cutoutSpacing) {
append(cutoutPositions, vector(x, y));
}
}
for (var cutoutPosition in cutoutPositions) {
var cutoutSketch = circleSketch(context, id + "cutoutSketch" + cutoutPosition, {
"center" : cutoutPosition,
"radius" : cutoutRadius
});
var cutoutExtrude = extrude(context, id + "cutoutExtrude" + cutoutPosition, {
"entities" : qSketchRegion(id + "cutoutSketch" + cutoutPosition),
"direction" : evOwnerSketchPlane(context, {
"entity" : qSketchRegion(id + "cutoutSketch" + cutoutPosition)
}).normal,
"endBound" : BoundingType.BLIND,
"endDepth" : definition.wallThickness,
"operationType" : NewBodyOperationType.REMOVE
});
}
});
function rectangleSketch(context is Context, id is Id, corners is map)
{
var sketch = newSketch(context, id, {
"sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});
skRectangle(sketch, "rectangle", {
"cornerA" : corners.cornerA,
"cornerB" : corners.cornerB
});
skSolve(sketch);
return sketch;
}
function circleSketch(context is Context, id is Id, parameters is map)
{
var sketch = newSketch(context, id, {
"sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});
skCircle(sketch, "circle", {
"center" : parameters.center,
"radius" : parameters.radius
});
skSolve(sketch);
return sketch;
}
0
Comments
You'll have to learn how to write FeatureScript yourself. But Onshape has some great learning material to get you started:
https://learn.onshape.com/courses/featurescript-fundamentals
Custom FeatureScript and Onshape Integrated Applications