Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

Help with BOOLEAN_BAD_INPUT

I'm experimenting with Booleans and wanted to run a test where I first create a subtraction Boolean, then union the resulting shape with a new one. However, I keep getting a BOOLEAN_BAD_INPUT error whenever I try to perform the final Boolean operation on the two shapes.

FeatureScript 2455;
import(path : "onshape/std/common.fs", version : "2455.0");

annotation { "Feature Type Name" : "My Feature", "Feature Type Description" : "" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// Define the parameters of the feature type
annotation { "Name" : "Plane", "Filter" : GeometryType.PLANE, "MaxNumberOfPicks" : 1 }
definition.plane is Query;
}
{
// Define the function's action

const eval_plane = evPlane(context, { "face" : definition.plane });

const sketch1Id = id + "sketch1Id";
const sketch1 = newSketchOnPlane(context, sketch1Id, {
"sketchPlane" : eval_plane
});

skRectangle(sketch1, "rectangle1", {
"firstCorner" : vector(-1, -1) * centimeter,
"secondCorner" : vector(1, 1) * centimeter
});


const sketch2Id = id + "sketch2Id";
const sketch2 = newSketchOnPlane(context, sketch2Id, {
"sketchPlane" : eval_plane
});

skRectangle(sketch2, "rectangle1", {
"firstCorner" : vector(-1 / 2, -1 / 2) * centimeter,
"secondCorner" : vector(1 / 2, 1 / 2) * centimeter
});

skSolve(sketch1);
skSolve(sketch2);

opExtrude(context, id + "extrude1", {
"entities" : qSketchRegion(sketch1Id),
"direction" : eval_plane.normal,
"endBound" : BoundingType.BLIND,
"endDepth" : 3 * centimeter
});

opExtrude(context, id + "extrude2", {
"entities" : qSketchRegion(sketch2Id),
"direction" : eval_plane.normal,
"endBound" : BoundingType.BLIND,
"endDepth" : 3 * centimeter
});

opBoolean(context, id + "bool1", {
"tools" : qCreatedBy(id + "extrude2", EntityType.BODY),
"targets" : qCreatedBy(id + "extrude1", EntityType.BODY),
"operationType" : BooleanOperationType.SUBTRACTION
});

const sketch3Id = id + "sketch3Id";
const sketch3 = newSketchOnPlane(context, sketch3Id, {
"sketchPlane" : eval_plane
});

skRectangle(sketch3, "rectangle1", {
"firstCorner" : vector(-1 / 2 + 0.8, -1 / 2 + 0.8) * centimeter,
"secondCorner" : vector(1 / 2 + 0.8, 1 / 2 + 0.8) * centimeter
});

skSolve(sketch3);

opExtrude(context, id + "extrude3", {
"entities" : qSketchRegion(sketch3Id),
"direction" : eval_plane.normal,
"endBound" : BoundingType.BLIND,
"endDepth" : 3 * centimeter
}); // Union the two shapes

const toolBodies = qUnion([qCreatedBy(id + "bool1", EntityType.BODY), qCreatedBy(id + "extrude3", EntityType.BODY)]);
try
{
opBoolean(context, id + "boolean2", {
"tools" : toolBodies,
"operationType" : BooleanOperationType.UNION
});
}
});

Document:
https://cad.onshape.com/documents/a14c56a245f5d916e2a230ba/w/d95735840e5ea068ad7e4b28/e/5be9b160494880d17f3e8cc8

Thanks in advance for any help 🙂

Best Answer

  • Jed_YeiserJed_Yeiser Member Posts: 38 PRO
    edited September 16 Answer ✓

    @jensen_brightman the issue is with your toolBodies variable, specifically the qCreatedBy(id + "bool1", EntityType.BODY)component. Booleans do not create bodies, so that query is invalid. I recommend using addDebugEntities to debug your code and check that your queries are actually correct.

    Boolean queries - in paticular - are confusing. The booleans don't create bodies, so any qCreatedBy that references a boolean will fail. However, booleans DO preserve the order of the input queries (the first query in the boolean will work after the boolean).

    if you change your toolBodies variable to: const toolBodies = qUnion([qCreatedBy(id + "extrude1", EntityType.BODY), qCreatedBy(id + "extrude3", EntityType.BODY)]);the code will work as intended. After the second boolean (see notes below about clearly labeling variables/operations), you can query the 'booleaned' body by using qcreatedBy(id + "extrude1", EntityType.BODY).

    It may be worth adding a bit more detail to your feature names - the generic 'extrude 1', 'bool1' can make it a little difficult to understand what's going on. This is not so much the case with short featurescripts like the one above, but certainly the case when you get into longer, more complicated processes.

Answers

  • Jed_YeiserJed_Yeiser Member Posts: 38 PRO
    edited September 16 Answer ✓

    @jensen_brightman the issue is with your toolBodies variable, specifically the qCreatedBy(id + "bool1", EntityType.BODY)component. Booleans do not create bodies, so that query is invalid. I recommend using addDebugEntities to debug your code and check that your queries are actually correct.

    Boolean queries - in paticular - are confusing. The booleans don't create bodies, so any qCreatedBy that references a boolean will fail. However, booleans DO preserve the order of the input queries (the first query in the boolean will work after the boolean).

    if you change your toolBodies variable to: const toolBodies = qUnion([qCreatedBy(id + "extrude1", EntityType.BODY), qCreatedBy(id + "extrude3", EntityType.BODY)]);the code will work as intended. After the second boolean (see notes below about clearly labeling variables/operations), you can query the 'booleaned' body by using qcreatedBy(id + "extrude1", EntityType.BODY).

    It may be worth adding a bit more detail to your feature names - the generic 'extrude 1', 'bool1' can make it a little difficult to understand what's going on. This is not so much the case with short featurescripts like the one above, but certainly the case when you get into longer, more complicated processes.

Sign In or Register to comment.