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.

Options

get featureList of parent feature from a query?

Evan_ReeseEvan_Reese Member Posts: 2,069 PRO
How can I take a query of a sketch edge, and get the featureList of the parent sketch? I know how to get the sketch Id, but I'm not sure where to go from there.
Evan Reese / Principal and Industrial Designer with Ovyl
Website: ovyl.io

Best Answers

  • Options
    _anton_anton Member, Onshape Employees Posts: 297
    Answer ✓
  • Options
    Jacob_CorderJacob_Corder Member Posts: 129 PRO
    Answer ✓
    @Evan_Reese
    Are you just trying to copy the sketch?
    this does it and keeps it as a sketch
     probably add construction filters if you want.
     FeatureScript 1977;
    import(path : "onshape/std/common.fs", version : "1977.0");
    
    annotation { "Feature Type Name" : "pattern Sketch" }
    export const patternSketch = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "sk Ent", "Filter" : EntityType.EDGE||EntityType.FACE, "MaxNumberOfPicks" : 1 }
            definition.skEnt is Query;     
            
        }
        {       
            var owner = lastModifyingOperationId(context, definition.skEnt)  as Id;
            owner = owner[0];
            owner = makeId(owner);
            
            opPattern(context, id+"Copy", {
                    "entities" : qCreatedBy(owner, EntityType.BODY),
                    "transforms" : [identityTransform()],
                    "instanceNames" : ["copySketchEnts"]
            });        
        });

Answers

  • Options
    _anton_anton Member, Onshape Employees Posts: 297
    Answer ✓
  • Options
    Jacob_CorderJacob_Corder Member Posts: 129 PRO
    edited March 2023
    @_anton is close, but to get the sketch features id you need take the first element in the id. So ownerSketchId[0] should do it.
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,069 PRO
    edited March 2023
    @_anton
    Thanks. I've gotten that far, but I'm wanting it formatted in whatever form applyPattern() ingests. I thought I might need to use featureList(), but I'm not sure.

    Something like this:
    applyPattern(context, id + "copySketch", {
                        "instanceFunction" : sketchId,
                        "patternType" : PatternType.FEATURE,
                        "transforms" : [identityTransform()],
    		    "instanceNames" : ["copy"],
                        "fullFeaturePattern" : false
                    }, identityTransform());

    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Options
    Jacob_CorderJacob_Corder Member Posts: 129 PRO
    Answer ✓
    @Evan_Reese
    Are you just trying to copy the sketch?
    this does it and keeps it as a sketch
     probably add construction filters if you want.
     FeatureScript 1977;
    import(path : "onshape/std/common.fs", version : "1977.0");
    
    annotation { "Feature Type Name" : "pattern Sketch" }
    export const patternSketch = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "sk Ent", "Filter" : EntityType.EDGE||EntityType.FACE, "MaxNumberOfPicks" : 1 }
            definition.skEnt is Query;     
            
        }
        {       
            var owner = lastModifyingOperationId(context, definition.skEnt)  as Id;
            owner = owner[0];
            owner = makeId(owner);
            
            opPattern(context, id+"Copy", {
                    "entities" : qCreatedBy(owner, EntityType.BODY),
                    "transforms" : [identityTransform()],
                    "instanceNames" : ["copySketchEnts"]
            });        
        });
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,069 PRO
    @Jacob_Corder
    Thanks for seeing through my wrong question and giving me the answer to the one I should have asked. That does accomplish what I'm after. I had done something similar, but I guess different enough to mess up other feature's ability to find the sketch plane direction. This should unblock me on what I'm working on!
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Options
    Jacob_CorderJacob_Corder Member Posts: 129 PRO
    @_anton is to receive credit, I didn't even think of using lastModificationFeatureId to extract it. I was surprised that opPattern actually copied the sketch as it is. I just tested it to see what would happen and boom a sketch. 
  • Options
    _anton_anton Member, Onshape Employees Posts: 297
    Team effort. :P
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,069 PRO
    Go team!
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.