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.
How to use the API to execute a FeatureScript to create a custom feature?
I created a Part Studio and a Feature Studio in the same document.
Here is the content of the Feature Studio.
FeatureScript 2581; import(path : "onshape/std/common.fs", version : "2581.0"); annotation { "Feature Type Name" : "Fillet Everything" } export const filletEverything = defineFeature(function(context is Context, id is Id, definition is map) precondition { } { opPlane(context, id + "plane1", { "plane" : plane(vector(0, 0, 6) * inch, vector(0, 0, 1)) }); });
As you can see, this script simply creates a plane. Now, I need to use the Onshape Python API to call this FeatureScript in the Part Studio to create a plane. My Python code is as follows:
body = {
"btType": "BTFeatureDefinitionCall-1406",
"features": [
{
"featureType": "filletEverything",
"btType": "BTMFeature-134",
"name": "Fillet Everything 1",
"parameters": [],
"featureId": "FGMsohIYH03BN1f_0",
"subFeatures": [],
"namespace": "e03fd799aee4796bff7177d98::m4c232d7c5b8456deef0ccc33",
"nodeId": "QtTe+DBU77uVY1dM",
"returnAfterSubfeatures": False,
"suppressed": False
}
],
}
res = self._api.request('post', '/api/v10/partstudios/d/' + did + '/w/' + wid + '/e/' + eid + '/features',
body=body)
The content of the body is obtained by calling the getFeatures
API, so the body content should be correct. However, whether I use the Python API or the API Explorer, I am unable to create the plane in the Part Studio. The error message returned is as follows(from python):
'{
"message" : "An internal error has occurred; support code 6a3cbb3b760a3d749babc43e",
"status" : 500,
"code" : 0,
"supportCode" : "6a3cbb3b760a3d749babc43e",
"moreInfoUrl" : ""
}'
Besides that, I have also tried using other versions of the API, such as v9, as well as the default API, but none of them were able to create the plane successfully. I believe the issue lies with the FeatureScript, because I can correctly create features like sketches and extrudes using a similar approach.
The reason for using the API to execute the FeatureScript is that, through FeatureScript, I can create a sketch plane by directly specifying the point coordinates and the normal (using the newSketchOnPlane
function). Since my data only contains the Origin, normal, and x information, I have no choice but to use this approach to create the sketch plane
If anyone has experience with executing FeatureScript scripts in a Part Studio via the API, or if you have any insights into what might be causing this issue, I’d really appreciate your help!