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.
I need a little help

I have one last error in my script that I can't get rid of.
Thank you for your support
Hansjürg
CODE:
FeatureScript 2559;
import(path : "onshape/std/common.fs", version : "2559.0");
// Annotation für den Feature-Typ
annotation { "Feature Type Name" : "Grid Generator" }
// Definition der Feature-Funktion
//export const GridGenerator = defineFeature; function(context, id, definition) {
export const GridGenerator = defineFeature;function(context is Context, id is Id, definition is map) {
// Precondition für Parameterdefinitionen precondition { annotation { "Name" : "Grid Spacing" } definition.spacing is LengthParameter({ "default" : 10 * millimeter, "min" : 0.1 * millimeter, "max" : 100 * millimeter }); annotation { "Name" : "Rows" } definition.rows is IntegerParameter({ "default" : 10, "min" : 1, "max" : 100 }); annotation { "Name" : "Columns" } definition.columns is IntegerParameter({ "default" : 10, "min" : 1, "max" : 100 }); annotation { "Name" : "Origin" } definition.origin is VectorParameter({ "default" : vector(0, 0, 0) });
}
// Erstellung des Skizzenobjekts auf der definierten Ebene const sketch = newSketchOnPlane(context, id + "sketch", { "plane" : plane(vector(0, 0, 0), vector(0, 0, 1)) }); // Vertikale Linien zeichnen for (var i = 0; i <= definition.columns; i += 1) { skLineSegment(sketch, "vertical" ~ i, { "start" : definition.origin + vector(i * definition.spacing, 0, 0), "end" : definition.origin + vector(i * definition.spacing, definition.rows * definition.spacing, 0) }); } // Horizontale Linien zeichnen for (var j = 0; j <= definition.rows; j += 1) { skLineSegment(sketch, "horizontal" ~ j, { "start" : definition.origin + vector(0, j * definition.spacing, 0), "end" : definition.origin + vector(definition.columns * definition.spacing, j * definition.spacing, 0) }); } // Die Skizze lösen skSolve(sketch);
};
Fault:
extraneous input 'precondition' expecting {'annotation', '[', '+', '-', 'return', 'if', 'for', 'while', 'new', '!', '++', '--', '::', 'function', 'operator', 'undefined', 'break', 'continue', 'var', 'const', 'try', 'in', 'switch', 'throw', SEMI, '{', '(', '}', BOOLEAN, NUMBER, ID, BUILTIN, STRING} |
| ||||||
---|---|---|---|---|---|---|---|
| |||||||
|
|
|
| 12:5 |
| Feature Studio 1 |
| ||
---|---|---|
Best Answer
-
NeilCooke Moderator, Onshape Employees Posts: 5,845
Compare and contrast - this is why you should not use ChatGPT, it's not even close…
FeatureScript 2615; import(path : "onshape/std/common.fs", version : "2615.0"); annotation { "Feature Type Name" : "Grid generator", "Feature Type Description" : "" } export const gridGenerator = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Grid spacing" } isLength(definition.spacing, { (millimeter) : [0.1, 100, 100] } as LengthBoundSpec); annotation { "Name" : "Rows" } isInteger(definition.rows, { (unitless) : [1, 10, 100] } as IntegerBoundSpec); annotation { "Name" : "Columns" } isInteger(definition.columns, { (unitless) : [1, 10, 100] } as IntegerBoundSpec); } { const sketch = newSketchOnPlane(context, id + "sketch", { "sketchPlane" : plane(vector(0, 0, 0) * millimeter, vector(0, 0, 1)) }); for (var i = 0; i < definition.columns; i += 1) { skLineSegment(sketch, "vertical" ~ i, { "start" : vector(i * definition.spacing, 0 * millimeter), "end" : vector(i * definition.spacing, definition.rows * definition.spacing) }); } for (var j = 0; j < definition.rows; j += 1) { skLineSegment(sketch, "horizontal" ~ j, { "start" : vector(0 * millimeter, j * definition.spacing), "end" : vector(definition.columns * definition.spacing, j * definition.spacing) }); } skSolve(sketch); });
Senior Director, Technical Services, EMEA3
Answers
Looks like ChatGPT to me - don't trust it.
Should be:
export const GridGenerator = defineFeature
(
function(context is Context, id is Id, definition is map) {
Also, no such keywords as LengthParameter, IntegerParameter, VectorParameter
Use the code snippets in the menu at the top of the Feature Studio for the correct syntax,
Why rejected answer?
The best place to learn FeatureScript is here. It isn't to hard and doesn't take too long either, you just have to watch the lessons. 😎
Onshape's FeatureScript Fundamentals Course
CADSharp's FeatureScript Course
.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Thank you for trying to help me.
I am an absolute greenhorn at feature scripting and have spent hours working with Perplexity and CahtGPT to come up with the above code.
Only the last error I can't get rid of.
It doesn't help much if you point out the lessons I need to learn. Which ones in this specific case?
I'm quite willing to learn something, but general hints won't get me anywhere:
What do I want to do anyway?
It is not possible to show a screen grid in Onshape. I would like this to give me a rough overview of the dimensions and the relationships.
This code should show a sketch with a line grid in it. If I can also set the spacing, that would be great.
xport const GridGenerator = defineFeature
(
function(context is Context, id is Id, definition is map) {
is also wrong
It's not wrong, you need to close the parenthesis at the end of the code too.
Well Neil already answered the question, I was just elaborating on how to not have this issue in the future:
Which lesson? All of them =)
The lessons are incremental, so each one builds on the previous lesson. This means you need to start at lesson 1. They teach you the foundation of FeatureScript so that you will understand how to make all kinds of features.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
// Annotation für den Feature-Typ
annotation { "Feature Type Name" : "Grid Generator" }
// Definition der Feature-Funktion
//export const GridGenerator = defineFeature; function(context, id, definition) {
export const GridGenerator = defineFeature ( function(context is Context, id is Id, definition is map) {
// Precondition für Parameterdefinitionen
precondition {
annotation { "Name" : "Grid Spacing" }
definition.spacing is LengthParameter({
"default" : 10 * millimeter,
"min" : 0.1 * millimeter,
"max" : 100 * millimeter
});
}
;}
Here are the faults:
> 9:44 Error in inializer function arguments
> 9:46 missing TOP_SEMI at 'function'
> 11:5 extraneous input 'precondition' expecting {'annotation', '[', '+', '-', 'return', 'if', 'for', 'while', 'new', '!', '++', '--', '::', 'function', 'operator', 'undefined', 'break', 'continue', 'var', 'const', 'try', 'in', 'switch', 'throw', SEMI, '{', '(', '}', BOOLEAN, NUMBER, ID, BUILTIN, STRING}
Hansjürg
Compare and contrast - this is why you should not use ChatGPT, it's not even close…
Yeah, you shouldn't use LLMs for this. They don't replace understanding, especially for a specialized language like FS. You'll get a nice-looking snippet quickly and then spend a hundred times as long finding the issues.
Michael's suggestion is really the answer here. Failing that, search the forum for custom features that already do this, or find similar custom features and understand their code.
Hello Neil
Many thanks for that.
It looks much clearer and more logical, even for a layman.