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.

Selecting Derived Sketch

papawopapawo Member, Developers Posts: 206 PRO


can somebody explain me , how to achieved this. I have sample code that I can use but I want to know the basic.
Tagged:

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 493
    I think the best way to do this is to use a feature input, and a utility function that gets a query for the entities in a feature list. Here's an example:
    annotation { "Feature Type Name" : "Select features" }
    export const multipleFeatures = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Feature" }
            definition.features is FeatureList;
        }
        {
            const entities = qCreatedBy(definition.features);
            debug(context, entities);
        });
    
    export function qCreatedBy(features is FeatureList) returns Query
    {    
        var query = [];
        for (var feature in features)
            query = append(query, qCreatedBy(feature.key));
        return qUnion(query);
    }

    Example document:
    https://cad.onshape.com/documents/de90c930e40cf8bcf4a5fb07/w/754c83eb6f9cb3ab6b29f73b/e/6437c056f266e6142585dc0b

  • papawopapawo Member, Developers Posts: 206 PRO
    edited January 2018
    can you explain the code? i want to hear it from the expert.
    why do it needs to have export before function?
    why is the debug shows resolves bodies?
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 493
    edited January 2018
    1. The export isn't necessary for this code, but it's there so the function could potentially be imported and reused somewhere else.

    2. The debug statement is there to demonstrate that the value of "entities" is the thing you're asking for (if it's not, let me know, you might need a different solution!).

      When using this in your code, you should remove the debug() line of code, and use the variable "entities" wherever you would have previously used "definition.profile". If "entities" is not a good variable name for your feature, you can replace it with a better one. After renaming, the old definition.profile input can be entirely removed from the precondition.
  • papawopapawo Member, Developers Posts: 206 PRO
    i like the debug as i can see the value of entities. I know I can comment out this too but Im confused why is it showing bodies resolved? is it creating bodies?
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 493
    Take a look at the documentation for EntityType and BodyType.

    In short: Bodies can be 3D, 2D, 1D, even 0D. Sketches create both 1D wire bodies (sketch edges) and 2D sheet bodies (sketch regions).
Sign In or Register to comment.