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 can I use FeatureScript to get the longest edge of a part as a computed property
elias_bonauer
Member Posts: 4 ✭✭
I try to create a feature script that lets me get the longest edge of a part as a computed property in a user defined table.
So far I had no success other than get the compuedVolume as shown in an example somewhere.
Can yomebody give me a hint or an example how to get all edges, find the logest and rturn that as a computed propery?
Any help is highly appreciated!
0
Best Answer
-
elias_bonauer Member Posts: 4 ✭✭Ok, i figured it out, I needed to use evaluateQuery and then return the value at index 0annotation { "Property Function Name" : "longestEdge" }
export const longestEdge = defineComputedPartProperty(
function(context is Context, part is Query, definition is map) returns ValueWithUnits
{
var longestEdge = evaluateQuery(context, qLargest(qOwnedByBody(part, EntityType.EDGE)));
return evLength(context, {
"entities" : longestEdge[0]
});
});
0
Answers
export const longestEdge = defineComputedPartProperty(
function(context is Context, part is Query, definition is map) returns ValueWithUnits
{
return evVolume(context, { "entities" : part });
});
Jacob wrote a feature to find the longest edge.
For a computed property, the query for part is given already so the code is a bit shorter:
Custom FeatureScript and Onshape Integrated Applications
export const longestEdge = defineComputedPartProperty(
function(context is Context, part is Query, definition is map) returns ValueWithUnits
{
var longestEdge = evaluateQuery(context, qLargest(qOwnedByBody(part, EntityType.EDGE)));
return evLength(context, {
"entities" : longestEdge[0]
});
});
Custom FeatureScript and Onshape Integrated Applications