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.
Using AI for FS generation.. and failing
fnxf
Member, User Group Leader Posts: 143 PRO
So yes, I'm no coder, but have been prompting ChatGPT to see if it can write me some code. I find the conversational style very engaging.
Here's my current non-working result:
https://cad.onshape.com/documents/ae1931dd79abf7662aea410a/w/7528de4b57e62d87e25e4f0c/e/aa2e0934fc6a93830a0bf384
Here's my current non-working result:
https://cad.onshape.com/documents/ae1931dd79abf7662aea410a/w/7528de4b57e62d87e25e4f0c/e/aa2e0934fc6a93830a0bf384
FeatureScript 1963; import(path : "onshape/std/geometry.fs", version : "1963.0"); import(path : "onshape/std/common.fs", version : "1963.0"); annotation { "Feature Type Name" : "Zugdreieck" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Base Curve", "Filter" : EntityType.EDGE_OR_SKETCH_CURVE } definition.baseCurve is Query; annotation { "Name" : "Extrude Height" } definition.extrudeHeight is value with unitType(distance); } { // Get the curve from the query const curve = definition.baseCurve; var curveGeometry; if (isEdge(curve)) { curveGeometry = evEdgeGeometry(context, {"edge" : curve}); } else if (isSketchCurve(curve)) { curveGeometry = evSketchCurveGeometry(context, {"sketchCurve" : curve}); } else { throw regenError("The selected entity is not a valid curve"); } // Get the length of the curve const b = length(curveGeometry); // Define the variables needed for the formula const h = definition.extrudeHeight.getValue() / 2.0; const l = sqrt(b * b / 2.0); // Create a sketch on the plane of the curve const sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : evPlane(context, {"curve" : curve}) }); // Draw the three lines using the formula const line1 = sketch1.lineTo(point(b, 0)); const line2 = sketch1.lineTo(point(b / 2.0, l)); const line3 = sketch1.lineTo(point(0, 0)); // Close the sketch sketch1.closePath(); // Extrude the sketch const extrude1 = newLinearExtrude(context, id + "extrude1", { "entities" : sketch1.id, "direction" : vector(0, 0, 1), "distance" : definition.extrudeHeight }); // Return the extruded solid return extrude1; });
Apparently there's an issue on line 13.. And I got the AI stumped as well ;-) because it keeps presenting "solutions" which give more errors ..
This was fun, and I wanted to share that
This was fun, and I wanted to share that
2
Comments
There's a node module for talking to chatgpt. It wouldn't be hard to stuff it full of feature scripts.
I guess someone should ask OS 1st & then how would you do it?
Is it "hey you this is a feature script" and then list the script in the dialog?
chatgpt api
Are there any other Node guys out there?
PS If you want to see what AI support can do you may want to check intellij's AI support (https://www.jetbrains.com/help/idea/ai-assistant.html). It is not perfect and it does not code while you sleep, but it's boosting development amazingly. For questions I searched the web for hours it gives hints within a few seconds. I think that would be a good benchmark to reach...
Creating an AI that can create a feature is more than just funneling featurescript into it. Doing that might produce code that doesn't have syntax errors, but going from a prompt to useable output requires labelled data. Someone needs to produce a dataset that has both featurescript and metadata describing that featurescript. Without labelled data, the prompt will just give a mish mash of random featurescript. Theres multiple layers of translation from text prompt to code to 3d model. AI isn't magic, behind a useful AI is an army of people creating training data to produce results. For languages like javascript, theres a mountain of user forums where someone asks "how do I do X in javascript", and the top answer is a single isolated line of code that does it. That doesn't exist for FeatureScript, someone would have to intentionally make that dataset.
Until then, if you want an easier way of producing a feature, hire a professional. You'll get better results, and I'm definitely faster than messing with chat gpt.
Custom FeatureScript and Onshape Integrated Applications