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.
How to set normal direction for a hole?
nikolas_engelhard
Member Posts: 5 ✭
Hey!
I'm trying to start with Feature Script and as first task tried to make a simple cylindrical hole. I let the user select a vertex on a surface, create a skect, draw a circle and then want to extrude a hole. My problem is currently the value for "oppositeDirection". How can I set this value (or the normal) so that the hole is created in the correct direction (aka within the object?)
My project is here (FS Hole just creates a Hole, the other Script should later add a hole for a nut)
https://cad.onshape.com/documents/6ce9fea6c453d84514e40287/w/85a62743a478dd09df2ba77d/e/c6922fdc600fcf2d5382534c
To test my Script, I create two rectangles on the top plane and extruded them in opposite directions (inside positive and negative z-space). I have to use different values for "oppositeDirection" to make the two holes.
In the current version, the user can set a flag ("invert normal') but of course this should not be the case in the final version.
Nikolas
I'm trying to start with Feature Script and as first task tried to make a simple cylindrical hole. I let the user select a vertex on a surface, create a skect, draw a circle and then want to extrude a hole. My problem is currently the value for "oppositeDirection". How can I set this value (or the normal) so that the hole is created in the correct direction (aka within the object?)
My project is here (FS Hole just creates a Hole, the other Script should later add a hole for a nut)
https://cad.onshape.com/documents/6ce9fea6c453d84514e40287/w/85a62743a478dd09df2ba77d/e/c6922fdc600fcf2d5382534c
To test my Script, I create two rectangles on the top plane and extruded them in opposite directions (inside positive and negative z-space). I have to use different values for "oppositeDirection" to make the two holes.
In the current version, the user can set a flag ("invert normal') but of course this should not be the case in the final version.
Nikolas
Tagged:
0
Comments
-
By default your extrude direction is dictated by the normal direction of the plane or surface that you sketched your point on. This is normally away from your part, which is usually the opposite of the direction of your hole. You can fix your default direction by just multiplying by -1. This will flip the direction. But it's a good idea to keep the invertNormal option just in case the user wants to flip the direction. Also, you can use the OPPOSITE_DIRECTION UIHint in order to make the interface match what you would normally see - a double arrow instead of a checkbox.

1 -
If you want the code to figure out which direction to extrude automatically, you can try to extrude it in one direction, and then extrude in the opposite direction if there was an error. That's what I do in my Mounting Boss featurescript.
So looking at your code, you could try something like this:var extrudeDefinition = { "entities" : qSketchRegion(id + "frontSketch", true), "direction" : sketchPlane.normal, "operationType" : NewBodyOperationType.REMOVE, "defaultScope" : true, "endBound" : BoundingType.UP_TO_SURFACE, "endBoundEntityFace" : definition.backface }; // Try to extrude in the normal direction first. // If that direction fails, then try again in the opposite direction. try silent { extrudeDefinition.oppositeDirection = false; extrude(context, id + "extrude1" + unstableIdComponent("Normal"), extrudeDefinition); } catch (error) { if (error.message == "EXTRUDE_FAILED") { extrudeDefinition.oppositeDirection = true; extrude(context, id + "extrude1" + unstableIdComponent("Reverse"), extrudeDefinition); } else { throw error; } }
1 -
In our feature implementations we usually take an approach of specifying
"Editing Logic Function" for the feature, which is executed during feature editing and can initialize some feature parameters based on simple analysis. e.g. flip of up-to-face extrude is computed by shouldFlipExtrudeDirection() function in extrude.fs, flip of hole direction - by holeScopeFlipHeuristicsCall in hole.fs . This way in simple case editing logic method guesses right and when it does not, the user can override its decision.
More here: https://cad.onshape.com/FsDoc/uispec.html#editing-logic-function
0 -
@nikolas_engelhard
You are calling 'extrude' with a 'direction' parameter. You'll notice that there is no 'direction' parameter in the 'extrude' documentation:
https://cad.onshape.com/FsDoc/library.html#extrude-Context-Id-map
This is because extrude uses evOwnerSketchPlane internally on its 'entities' input to find the direction.
If you would like to manually specify the extrude direction, you can use opExtrude instead (but this function will not allow you to do the 'operationType' work you are trying to do, so I think 'extrude' is probably the right call to use):
https://cad.onshape.com/FsDoc/library.html#opExtrude-Context-Id-map
I think what you'll want to do is something like the following:// Find the point on the center of the back face const backFacePoint = evFaceTangentPlane(context, { "face" : definition.backFace, "parameter" : vector(0.5, 0.5) }).origin; // Construct the vector pointing from the center to the beck face point const towardsBackFace = backFacePoint - location; // extrude should be 'oppositeDirection' if the vector pointing towards // back face is not in the hemisphere "forward" of the sketch plane const oppositeDirection = dot(sketchPlane.normal, towardsBackFace) < 0; // Then use "oppositeDirection" directly in your extrude call
Jake Rosenfeld - Modeling Team1 -
Thanks for your help! I used the analytical way from @Jake_Rosenfeld (now also with the added hole for the nut)
1 -
@Jake_Rosenfeld ; will the geometry.fs version of extrude() ever take a direction input? Asking since there are of course some options available there that are not within opExtrude.
0 -
@Jonathan_Hutchinson What exactly are you trying to do? Extrude will automatically extrude along the vector normal to the face selected, or you can use oppositeDirection if you need it flipped. If there needs to be along a different direction, you'll probably have better luck trying a sweep or loft.
Applications Developer at Premier Custom Built
chadstoltzfus@premiercb.com0 -
Evailable now

1




