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 up to face - Why wont this work?
matthew_roche
Member Posts: 8 ✭✭
Hi Guys, Loving feature script but I am new to it. Hope this is not too much of a Noob question.
I am trying to extrude a rectangle in a sketch on a face of a rectangular part to extrude out to the 'opposing' face. I have tried a multitude of ways to do this without any success. My last try which looks like it should work is below in full but I get EXTRUDE FAILED error in the feature script notices. Note it is part of a bigger script, I just pulled out the problem area for clarity. What Am I doing wrong? Any help would be much appreciated.
This is the outcome of the bad extrude:
If I use a blind extrude it works but I want the extrude to go up to the face. This means all my other code is OK. This is the extrude I used:
The Extrude works but not what I want.
I am trying to extrude a rectangle in a sketch on a face of a rectangular part to extrude out to the 'opposing' face. I have tried a multitude of ways to do this without any success. My last try which looks like it should work is below in full but I get EXTRUDE FAILED error in the feature script notices. Note it is part of a bigger script, I just pulled out the problem area for clarity. What Am I doing wrong? Any help would be much appreciated.
</code>FeatureScript 1403; import(path : "onshape/std/geometry.fs", version : "1403.0"); annotation { "Feature Type Name" : "Adder" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { /* Select a Face and an Edge to add a bump onto using a sketch */ annotation { "Name" : "face to AddTo", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.SlotFace is Query; annotation { "Name" : "Edge to Bump", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 } definition.SlotEdge is Query; } { /* Find the the plane for my sketch */ var endPoints is Query = qAdjacent(definition.SlotEdge, AdjacencyType.VERTEX, EntityType.VERTEX); var startPosition is Vector = evVertexPoint(context, { "vertex" : qNthElement(endPoints, 0) }); var endPosition is Vector = evVertexPoint(context, { "vertex" : qNthElement(endPoints, 1) }); var xDirection is Vector = normalize(endPosition - startPosition); var zDirection is Vector = evPlane(context, { "face" : qNthElement(definition.SlotFace, 0) }).normal; var cSys is CoordSystem = coordSystem(startPosition, xDirection, zDirection); var sketchPlane is Plane = plane(cSys); /* Draw a rectangle that extends 50mm beyond the edge on the face of my extrude */ var sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : sketchPlane }); var BumpHeight is ValueWithUnits = norm((endPosition - startPosition)/2); skRectangle(sketch1, "rectangle1", { "firstCorner" : vector(0 * millimeter, -50 * millimeter), "secondCorner" : vector(BumpHeight, 50 * millimeter) }); skSolve(sketch1); /* get the opposite face to my sketch face to extrude up to */ var regionToExtrude = qContainsPoint(qSketchRegion(id + "sketch1"), cSys.origin); var FaceBody1 = qOwnerBody(qNthElement(definition.SlotFace, 0)); var ParallelFaces = qFacesParallelToDirection(qOwnedByBody(FaceBody1, EntityType.FACE), xDirection); debug(context,qNthElement(ParallelFaces, 1)); /* Extrude to create my bump */ opExtrude(context, id + "extrude1", { "entities" : regionToExtrude, "direction" : evOwnerSketchPlane(context, {"entity" : regionToExtrude}).normal, "endBound" : BoundingType.UP_TO_FACE, "endBoundEntity" : qNthElement(ParallelFaces, 1), //Hardcoded the opposite face for this example "startBound" : BoundingType.UP_TO_FACE, "startBoundEntity" : qNthElement(ParallelFaces, 1) //Hardcoded the opposite face for this example<br> }); /* Add it all up to one part */ opBoolean(context, id + "boolean1", { "tools" : qCreatedBy(id + "extrude1", EntityType.BODY), "targets" : FaceBody1, "operationType" : BooleanOperationType.UNION, "targetsAndToolsNeedGrouping" : true }); }); </pre><h2><br><br><pre class="CodeBlock"><code>
This is the outcome of the bad extrude:
If I use a blind extrude it works but I want the extrude to go up to the face. This means all my other code is OK. This is the extrude I used:
/* Extrude to create my bump */ opExtrude(context, id + "extrude1", { "entities" : regionToExtrude, "direction" : evOwnerSketchPlane(context, {"entity" : regionToExtrude}).normal, "endBound" : BoundingType.BLIND, "startBound" : BoundingType.BLIND, "startDepth" : 12 * millimeter, "endDepth" : 0 * millimeter });
The Extrude works but not what I want.
0
Comments
FYI: It has saved me a ton of trouble writing this feature script. I will be doing a lot more of this. How do I publish my scripts for others to use?
You could get around this by having your extrude point in the right direction. There's a couple of different ways you could do it, but it depends on your specific implementation. The laziest way to do it would proably be to break your extrudes up into two seperate extrudes, with each inside their own try{} statement. Then the opExtrude facing the wrong direction will fail without breaking your FS, and the one with the right direction will work (theoretically, at least).