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.
Custom FeatureScript API evaluate
daniel_zeng842
Member Posts: 4 EDU
Hi!
I was looking for a way to get information out of a FeatureScript, and I noticed there were several forum posts suggesting to use the API call "evaluate_featurescript":
https://forum.onshape.com/discussion/11342/evaluate-existing-featurescript-using-api
I'm wondering if someone can further elaborate on something similar to https://forum.onshape.com/discussion/5382/whats-a-complete-api-call-to-partstudios-featurescript-look-like (I believe now making a reference to custom feature code should be possible given that it was 5 years ago).
I currently have the following code, and I just want to see if I can get either the length or the "0" from the custom feature:
API call for evaluate_featurescript:
Custom FeatureScript:
I was looking for a way to get information out of a FeatureScript, and I noticed there were several forum posts suggesting to use the API call "evaluate_featurescript":
https://forum.onshape.com/discussion/11342/evaluate-existing-featurescript-using-api
I'm wondering if someone can further elaborate on something similar to https://forum.onshape.com/discussion/5382/whats-a-complete-api-call-to-partstudios-featurescript-look-like (I believe now making a reference to custom feature code should be possible given that it was 5 years ago).
I currently have the following code, and I just want to see if I can get either the length or the "0" from the custom feature:
API call for evaluate_featurescript:
{ "script" : "function (context is Context, queries is map) { return skribfunc(context, newId(), queries); }", "queries" : [ { "key" : "Length", "value" : [ "4 in" ] } ], "sourceMicroversion" : f["sourceMicroversion"] }\
Where f is gotten from an API call to get the feature list.
(I have tried it with "script" : "function (context is Context, queries is map) { return skrib(context, newId(), queries); }", as well and both scripts resulted in "u'Function skribfunc with 3 argument(s) not found'")
(I have tried it with "script" : "function (context is Context, queries is map) { return skrib(context, newId(), queries); }", as well and both scripts resulted in "u'Function skribfunc with 3 argument(s) not found'")
Custom FeatureScript:
FeatureScript 1511; import(path : "onshape/std/geometry.fs", version : "1511.0"); annotation { "Feature Type Name" : "skrib" } export const skrib = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Length" } isLength(definition.Length, LENGTH_BOUNDS); } { println(definition.Length); return "0"; }); function skribfunc(context is Context, id is Id, entities is Query) { println(entities.Length); return "0"; }
0
Best Answer
-
caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭My suggestion is to make another featurescript in another tab that has no access to your modified laser joint function.
In there create a test function to see if you can get the result you want to eventually get through the API (in this case a "getVariable")
Once you know your FS code works, then move it into the API call. Debugging FS code in an API application is much more difficult than working out the kinks inside of Onshape. In onshape you can do helpful things like addDebugEntities to check if you're doing it correctly.1
Answers
With that being said, its also hard to suggest a fix for you because I don't understand what your goal is. The query that you've provided in your API call is also not valid. The skribfunc also isn't clear what its purpose is, as the Query datatype doesn't have a "Length" property. Could you expand on what you're trying to do?
For skribfunc, I wasn't too sure if there was a difference between a "feature" and a "function" based on https://onshape-public.github.io/docs/featureaccess/#custom-features. I was just trying random things to try to get the function found error fixed.
If you have any tips for how to approach this, it would be very helpful.
Most features don't actually store anything, they just modify the model. If you wrote the FS yourself, you could use "setAttribute" to store data, but the laser joint feature doesn't do that. (You could make your own version of it that does this, given that the code is public). You can then use the evaluate_featurescript (or just another featurescript) to get the attributes and thus the information you want.
alternatively you could use "lastModifyingOperationId" on every individual edge in the model, and then find the ones that have an operation id that matches the laser joint (you'd have to set the rollback bar to just after the laser joint feature). But I'm not sure if you'd then be able to find the pairs, it would jsut tell you what has been modified.
if I have the following in the FeatureScript: setVariable(context, "laser", definition.length);
I'm not too sure the second idea would work because the laser joint would modify 4 edges in total (given one tab and one base) and there would be no way to easily distinguish which ones would correspond to each other. Thank you for the idea though.
In there create a test function to see if you can get the result you want to eventually get through the API (in this case a "getVariable")
Once you know your FS code works, then move it into the API call. Debugging FS code in an API application is much more difficult than working out the kinks inside of Onshape. In onshape you can do helpful things like addDebugEntities to check if you're doing it correctly.