Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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_LessardHugues_Lessard Member Posts: 2

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

  • Ace_CaoileAce_Caoile Member Posts: 11 PRO

    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

  • _anton_anton Member, Onshape Employees Posts: 542 image
    edited June 2

    You can just throw in the code if evaluateQuery(context, definition.width->qOwnerBody())->size() != 1

    To explain the arrow thing: a->foo(b, c) is equivalent to foo(a, b, c).

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.