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.

Extruding in for loop

josh_crowsonjosh_crowson Member Posts: 7 EDU
edited March 2017 in FeatureScript
I am working on a mortise and tendon joint in feature script.  I know there is already one that exists, but it does not do exactly what I want.  This also pushes me to finally learn FS.  
FeatureScript 543;
import(path : "onshape/std/geometry.fs", version : "543.0");

annotation { "Feature Type Name" : "MortisetAndTennon" }
export const MortisetAndTennon = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
    annotation { "Name" : "tennon faces", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 100 }
    definition.tennonFaces is Query;
    // annotation { "Name" : "slot faces", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 100 }
    // definition.slotFaces is Query;
    
    
    }
    {
    var count = 0;
    const facesList = evaluateQuery(context, definition.tennonFaces);
    for (var face in facesList)
    {
        count = count + 1; 
        const plane = evPlane(context, { "face" : face});
        debug(context, plane);
        const sk = newSketchOnPlane(context, id + "sk" + toString(count), {"sketchPlane" : plane});
        skRectangle(sk, "rectangle1", { "firstCorner" : vector(0, 3) * inch, "secondCorner" : vector(1, 5) * inch });
        debug(context, sk);
        skSolve(sk);
        
        opExtrude(context, id + "extrude" + toString(count), {
                "entities" : qSketchRegion(id + "sk" + toString(count), true),
                "direction" : plane.normal,
                "endBound" : BoundingType.BLIND,
                "endDepth" : 1 * inch
        });
    }
    
    });



When I run the feature, Onshape says "Invalid state at the end of execution"  and "@skSolve: Parent Id F41vOgQIuzuAHks_2.sk used at two non-contiguous points in operation history (Cannot have F41vOgQIuzuAHks_2.extrude.1 between F41vOgQIuzuAHks_2.sk.1 and F41vOgQIuzuAHks_2.sk.2)".
It works though when I only select one face or if I comment out the extrude.  

Best Answer

Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited March 2017
    Welcome!

    For the error, check out the documentation for Ids here. You'll want to set the extrude's id to either id + count + "extrude", or id + ("extrude" ~ count)

    To get the corners of the sketch, you can query for e.g. sketchEntityQuery(id + "sketch1", EntityType.VERTEX, "rectangle1.left.start")
  • josh_crowsonjosh_crowson Member Posts: 7 EDU
    edited March 2017
    Thank you for the quick response.  Your comments helped with the extruding issue.  

  • MacColtelliMacColtelli Member Posts: 2
    Hello @ilya_baran
    I was trying to delete the multiple sketches and extrusions that I created in my for loop. When I used the "extrude" + i format I was able to query all iterations using qCreatedBy( id + "extrude") However, when I used your proposed version the for loop works which is great! but the query I showed fails to return anything. How do you suppose I query the bodies created by the iterations of my for loop?
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,648
    @MacColtelli probably best to have a "parent" id then make all sketches and extrudes children of that such as id + "loop" + ("sketch" ~ i) and id + "loop" + ("extrude" ~ i) then you can query id + "loop" to get everything. 
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.