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.
Question - Query with multiple picks to be limited to pick on a single body/part only
Hugues_Lessard
Member Posts: 2 PRO
Hi,
I am trying to code a featurescript that ask the user to pick 2 planes and return the distance between the 2 planes as Width. The two planes are selected as part of a single query :
annotation { "Name" : "Width", "Filter" : GeometryType.PLANE, "MaxNumberOfPicks" : 2 }
definition.width is Query;
To make it more robust, I would like to prevent the user from picking 2 planes that are on 2 different bodies as I want to get the width of a single part through this featurescript. In other words, I would like the featurescript to check the query with the 2 planes and determine the number of bodies that match the plane's query. Afterward, I would throw a regen error if the number of bodies is different from 1.
I tried to get the information through a qOwnedBy without success.
If there is another way around to ensure only 1 body is picked through a query for planes, please suggest it. I am open to go another way around.
Code for reference :
FeatureScript 2960;
import(path : "onshape/std/common.fs", version : "2960.0");
{
annotation { "Name" : "Width", "Filter" : GeometryType.PLANE, "MaxNumberOfPicks" : 2 }
definition.width is Query;
}
{
var width = evDistance(context, {
"side0" : qNthElement(definition.width, 0),
"side1" : qNthElement(definition.width, 1)
}).distance;
setProperty(context, {
"entities" : qOwnerBody(definition.width),
"propertyType" : PropertyType.CUSTOM,
"customPropertyId" : "69d79b5aef010a6d5acfcc01",
"value" : width
};
};
Comments
I'm also interested if this can be done… In my case I have a partstudio with bunch of sheet metal parts with varying thickness and I want to limit the user to pick only sheet metal parts with a specified thickness
You can just throw in the code if
evaluateQuery(context, definition.width->qOwnerBody())->size() != 1To explain the arrow thing:
a->foo(b, c)is equivalent tofoo(a, b, c).@_anton This filters out the invalid selections only… But is it possible to make it so that invalid selections are not even clickable to the users? right now I got a bunch of sheet metal bodies with varying thickness, so I manually hide invalid bodies first before making the selection. I'm looking to refactor my fs to something wherein the user can't even select the invalid bodies to begin with. Thanks
Edit: I guess what I'm trying to ask is if it's possible to set in the precondition portion of the script so that only sheet metal bodies with specific thickness becomes selectable to the user