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.
Variable Extrude
jack_white396
Member Posts: 7 EDU
I am trying the vary which direction I do an extrude based on where there is material. Essentially, this feature will take a point and make a specific hole pattern and extrude them, but if the point is on the opposite side of an object the feature does not work since there is nothing to be subtracted. I need to somehow be able to vary which direction I extrude based on where the point I select is in relation to the object I want extruded through. Here is my code- https://cad.onshape.com/documents/dd9b41942bbf9f447e9d9d6d/w/2b64a0a98ab7927062949adf/e/d176417788ab53093aeccb69
0
Answers
-
Hi @jack_white396, welcome to FeatureScript!
Try something like this:This will measure the z distance of the point with respect to the plane. If the point is in the opposite direction of the plane, the distance will be a negative value.const distance = worldToPlane3D(planey, point[2]);
A vector is an array, if you ever need the other values of the vector:const x = point[0]; const y = point[1]; const z = point[2];
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________0 -
@MichaelPascoe thanks for that advice but what if my plane and point is not in the z direction? As if how do I tell whether I need to use the x, y, or z distances?
0 -
I usually measure normal to the plane I'm using, z. This is the local z of the plane, not the global Z of the studio. Can you describe your goal a little more? You may need more inputs, something that you can extract a plane from.
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________0 -
@MichaelPascoe In this example, the point right in the middle of the circle is the point I want. however, the distance between this point and the face of the sphere is along the x axis, not the z. How do I get it to measure the correct way no matter which way the body is oriented?

0 -
If the cylinder will always be in the part studio, you can have the input be a cylindrical face. One click, I will show you if that is what you want, but I'm still a little confused. What is the feature expected to do? Is there always only a cylinder, or will there be other shapes and conditions?
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________0 -
The cylinder is just an object to test on. I am a member of an frc robotics team, and we often have to design parts to hold bearings in them. The idea of this feature is that the user can select a center point and then the bearing hole and three holes around it for rivets to hold the bearing in would automatically be made in the part.0
-
@jack_white396
Try using an implicit mate connector. If you need to measure the distance instead of a manual entry, you can use the above technique that I mentioned and measure from the startPlane.
Code:https://cad.onshape.com/documents/321704cdfedd9bd658ec2def/w/7ed9842c4e5b566356122040/e/29a0ec328e10902c13fd7099?renderMode=0&uiState=62750ae856487c0b606403caFeatureScript 1746; import(path : "onshape/std/geometry.fs", version : "1746.0"); annotation { "Feature Type Name" : "Bearing mount" } export const bearingMount = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Start location", "Filter" : BodyType.MATE_CONNECTOR || BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 } definition.mate is Query; annotation { "Name" : "Distance" } isLength(definition.distance, LENGTH_BOUNDS); } { const startCsys = evMateConnector(context, { "mateConnector" : definition.mate }); const startPlane = plane(startCsys); const point = startPlane.origin; const cent = worldToPlane(startPlane, point); const addition1 = vector(0, .690625) * inch; const addition2 = vector(((0.690625/2)*sqrt(3)), (-1*(0.690625/2))) * inch; const addition3 = vector((-1*((0.690625/2)*sqrt(3))), (-1*(0.690625/2))) * inch; const cent2 = (cent+addition1); const cent3 = (cent+addition2); const cent4 = (cent+addition3); const sketch1 = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : startPlane }); skCircle(sketch1, "circle1", { "center" : cent, "radius" : (1.125/2) * inch }); skCircle(sketch1, "circle2", { "center" : cent2, "radius" : (5/64) * inch }); skCircle(sketch1, "circle3", { "center" : cent3, "radius" : (5/64) * inch }); skCircle(sketch1, "circle4", { "center" : cent4, "radius" : (5/64) * inch }); skSolve(sketch1); extrude(context, id + "extrude1", { "entities" : qSketchRegion(id + "sketch1"), "endBound" : BoundingType.BLIND, "depth" : definition.distance, "oppositeDirection" : true, "operationType" : NewBodyOperationType.REMOVE, "booleanScope" : qAllNonMeshSolidBodies(), }); // opExtrude(context, id + "extrude1", { // "entities" : qSketchRegion(id + "sketch1"), // "direction" : -planey.normal, // "endBound" : BoundingType.THROUGH_ALL, // }); });
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________1
