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.
FeatureScript Extrude Help
robert_morris
OS Professional, Developers Posts: 169 PRO
I'm working on a new FeatureScript and could use a little help.
Inside of the script, it is creating a sketch and then using the extrude function to create the feature. I'm using the 'extrude' function instead of 'opExtrude' because I also want the option of adding a draft to the feature at the same time.
I want the user to be able to just select the part the feature should be attached to and automatically determine the correct direction to extrude the sketch.
I've tried doing something like the code below, but it doesn't seem to work. I'm hoping someone can explain why and help me figure out the correct way to do it.
Inside of the script, it is creating a sketch and then using the extrude function to create the feature. I'm using the 'extrude' function instead of 'opExtrude' because I also want the option of adding a draft to the feature at the same time.
I want the user to be able to just select the part the feature should be attached to and automatically determine the correct direction to extrude the sketch.
I've tried doing something like the code below, but it doesn't seem to work. I'm hoping someone can explain why and help me figure out the correct way to do it.
try<br> {<br> extrude(context, id + "Extrude1", {<br> "entities" : qSketchRegion(id + "Sketch1"),<br> "endBound" : BoundingType.UP_TO_BODY,<br> "endBoundEntityBody" : definition.booleanScope,<br> "oppositeDirection" : true,<br> "hasDraft" : definition.hasDraft,<br> "draftAngle" : definition.draftAngle,<br> "draftPullDirection" : false,<br> "operationType" : NewBodyOperationType.ADD,<br> "defaultScope" : false,<br> "booleanScope" : definition.booleanScope<br> });<br> }<br> catch (error)<br> {<br> if (error.message == "EXTRUDE_FAILED")<br> {<br> extrude(context, id + "Extrude1", {<br> "entities" : qSketchRegion(id + "Sketch1"),<br> "endBound" : BoundingType.UP_TO_BODY,<br> "endBoundEntityBody" : definition.booleanScope,<br> "oppositeDirection" : false,<br> "hasDraft" : definition.hasDraft,<br> "draftAngle" : definition.draftAngle,<br> "draftPullDirection" : false,<br> "operationType" : NewBodyOperationType.ADD,<br> "defaultScope" : false,<br> "booleanScope" : definition.booleanScope<br> });<br> }<br> else<br> {<br> throw error;<br> }<br> }
Tagged:
1
Comments
The specific hiccup in your code is that FeatureScript operations still get logged in the journal, even when the feature fails. That means the id for a failing extrude still needs to be unique, and the error your getting (albiet cryptically) is the result of those two duplicate ids. If you use ids and ...then you can still identify the result (e.g. with qCreatedBy) via the subId id + "Extrude1".
Working example:
https://cad.onshape.com/documents/dd02c4411a70818edc6cb508/w/cea1260bc5382d8f41f34f8a/e/627ada164a697875af6de874
The journal thing makes sense since it needs to keep track of features in the tree that might fail.
Thanks Kevin.
To let the Part Studio know that the "forward" and "reverse" parts of the id shouldn't be used for disambiguation in the queries generated for downstream features, you should instead use and The document shared above now has a test case to demonstrate the references maintained with this technique.