<p>Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.</p></p><strong>First time visiting? Here are some places to start:</strong></p><ol style="list-style:inherit;margin-left:25px;"><li>Looking for a certain topic? Check out the <a href="https://forum.onshape.com/categories">categories filter</a> or use Search (upper right).</li><li>Need support? <a href="https://forum.onshape.com/post/question/community-support">Ask a question</a> to our <a href="https://forum.onshape.com/categories/community-support">Community Support</a> category.</li><li>Please submit support tickets for bugs but you can request improvements in the <a href="https://forum.onshape.com/categories/product-feedback">Product Feedback category</a>.</li><li>Be respectful, on topic and if you see a problem, Flag it.</li></ol><p>If you would like to contact our Community Manager personally, feel free to <a href="https://forum.onshape.com/profile/6/LouGallo">send a private message</a> or <a href="mailto:lgallo@onshape.com">an email</a>.
</p>

get featureList of parent feature from a query?

EvanReese
EvanReese Member, Mentor Posts: 3,084 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
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com

Best Answers

  • Jacob_Corder
    Jacob_Corder Member Posts: 141 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

  • Jacob_Corder
    Jacob_Corder Member Posts: 141 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.
  • EvanReese
    EvanReese Member, Mentor Posts: 3,084 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
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Jacob_Corder
    Jacob_Corder Member Posts: 141 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"]
            });        
        });
  • EvanReese
    EvanReese Member, Mentor Posts: 3,084 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
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Jacob_Corder
    Jacob_Corder Member Posts: 141 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. 
  • _anton
    _anton Member, Onshape Employees Posts: 553 image
    Team effort. :P
  • EvanReese
    EvanReese Member, Mentor Posts: 3,084 PRO
    Go team!
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com