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.
Can someone help me out?
Dylan_Stewart
Member, Developers Posts: 107 PRO
Hello everyone,
I am trying to make a very simple hole feature that is driven off of FS sketches.
I am trying to eliminate all mouse clicks.
It seems very simple, I'm just missing something small.
This is the intended outcome of what I want the code to do.
and here is the code that I have so far.
Thanks!
I am trying to make a very simple hole feature that is driven off of FS sketches.
I am trying to eliminate all mouse clicks.
It seems very simple, I'm just missing something small.
This is the intended outcome of what I want the code to do.
and here is the code that I have so far.
FeatureScript 392;
import(path : "onshape/std/geometry.fs", version : "392.0");
annotation { "Feature Type Name" : "Hole Cut Out" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Width" }
isLength(definition.width, LENGTH_BOUNDS);
annotation { "Name" : "Height" }
isLength(definition.height, LENGTH_BOUNDS);
annotation { "Name" : "Material Thickness" }
isLength(definition.thickness, LENGTH_BOUNDS);
}
{
var width = definition.width;
var height = definition.height;
var holeX = width / 2;
var holeY = height / 2;
var squareVerticies = [
vector(0 * inch, 0 * inch),
vector(0 * inch, height),
vector(width, height),
vector(width, 0 * inch)];
var holeVerticies = [
vector(holeX, holeY)];
var sketch1 = newSketch(context, id + "sketch1", {
"sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});
skLineSegment(sketch1, "line1", {
"start" : squareVerticies[0],
"end" : squareVerticies[1]
});
skLineSegment(sketch1, "line2", {
"start" : squareVerticies[1],
"end" : squareVerticies[2]
});
skLineSegment(sketch1, "line3", {
"start" : squareVerticies[2],
"end" : squareVerticies[3]
});
skLineSegment(sketch1, "line4", {
"start" : squareVerticies[3],
"end" : squareVerticies[0]
});
skSolve(sketch1);
var holeSketch = newSketch(context, id + "Hole", {
"sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});
skCircle(holeSketch, "circle1", {
"center" : holeVerticies[0],
"radius" : 1 * inch
});
skSolve(holeSketch);
extrude(context, id + "extrude1", {
"entities" : qSketchRegion(id + "sketch1"),
"endBound" : BoundingType.SYMMETRIC,
"depth" : definition.thickness
});
extrude(context, id + "HoleExtrude", {
"entities" : qSketchRegion(id + "holeSketch"),
"endBound" : BoundingType.THROUGH_ALL,
"bodyType" : ToolBodyType.SURFACE,
"hasSecondDirection" : true,
"secondDirectionBound" : SecondDirectionBoundingType.THROUGH_ALL
});
opBoolean(context, id + "boolean1", {
"tools" : qCreatedBy(id + "HoleExtrude", EntityType.FACE),
"operationType" : BooleanOperationType.SUBTRACTION
});
});
Thanks!
Digital Engineering
0
Best Answer
-
mahir Member, Developers Posts: 1,307 ✭✭✭✭✭Fixed that for ya. You can use a skRectangle. Also, the hole extrude was calling out the wrong sketch name. I added an opDeleteBodies to get rid of the sketches.
</code></pre><pre class="CodeBlock"><code><pre class="CodeBlock"><code>FeatureScript 392; import(path : "onshape/std/geometry.fs", version : "392.0"); annotation { "Feature Type Name" : "Hole Cut Out" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Width" } isLength(definition.width, LENGTH_BOUNDS); annotation { "Name" : "Height" } isLength(definition.height, LENGTH_BOUNDS); annotation { "Name" : "Material Thickness" } isLength(definition.thickness, LENGTH_BOUNDS); } { var width = definition.width; var height = definition.height; var holeX = width / 2; var holeY = height / 2; var squareVertices = [ vector(0 * inch, 0 * inch), vector(width, height)]; var holeVertices = [ vector(holeX, holeY)]; var sketch1 = newSketch(context, id + "sketch1", { "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE) }); skRectangle(sketch1, "rectangle1", { "firstCorner" : squareVertices[0], "secondCorner" : squareVertices[1] }); skSolve(sketch1); var holeSketch = newSketch(context, id + "holeSketch", { "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE) }); skCircle(holeSketch, "circle1", { "center" : holeVertices[0], "radius" : 1 * inch }); skSolve(holeSketch); extrude(context, id + "extrude1", { "entities" : qSketchRegion(id + "sketch1"), "endBound" : BoundingType.SYMMETRIC, "depth" : definition.thickness }); extrude(context, id + "HoleExtrude", { "entities" : qSketchRegion(id + "holeSketch"), "endBound" : BoundingType.THROUGH_ALL, "operationType" : NewBodyOperationType.REMOVE, "hasSecondDirection" : true, "secondDirectionBound" : SecondDirectionBoundingType.THROUGH_ALL }); opDeleteBodies(context, id + "deleteBodies1", { "entities" : qUnion([qCreatedBy(id + "sketch1"), qCreatedBy(id + "holeSketch")]) }); });
1
Answers
You should check out the help file for the extrude command. It goes into more detail.
I'll look at the help file and see what I can come up with....
Seems like it's something really small and I'm just overlooking it.