Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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_crowson
Member Posts: 7 EDU
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.
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.
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.
Tagged:
1
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,210Part of the poor error reporting is a known bug; the reason the second extrude is failing is that the ids are hiearchical and the "loop" portion of the id must come before the "individual operation" portion of the id. So use
id + count + "extrude"
instead of
id + "extrude" + count
To query the points of a sketch, depends on what exactly you're looking for -- For example, qBodyType(qCreatedBy(sketchId, EntityType.VERTEX), BodyType.SHEET) will give you region corners, while qBodyType(qCreatedBy(sketchId, EntityType.VERTEX), BodyType.WIRE) will give you (possibly duplicated) sketch entity endpoints.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc6
Answers
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")
id + count + "extrude"
instead of
id + "extrude" + count
To query the points of a sketch, depends on what exactly you're looking for -- For example, qBodyType(qCreatedBy(sketchId, EntityType.VERTEX), BodyType.SHEET) will give you region corners, while qBodyType(qCreatedBy(sketchId, EntityType.VERTEX), BodyType.WIRE) will give you (possibly duplicated) sketch entity endpoints.
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?