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.
booleanBodies not working

Hi, I am pretty new to featurescript and I do have the issue, that my custom feature is only working sometimes (rarely). Some times it does what it should do and sometimes it just doesn't (without any errors).
The goal of this Custom Feature is to use a sketch with points as reference and create a hexagonal substraction on every point of the sketch. This feature should work on "normal" parts as well as sheet metal parts.
When it's not working it only creates this shadow of the hexagon.
FeatureScript 2599; import(path : "onshape/std/common.fs", version : "2599.0"); export enum MyHexSizes { annotation { "Name" : "M3" } m3, annotation { "Name" : "M4" } m4, annotation { "Name" : "M5" } m5, annotation { "Name" : "M6" } m6, annotation { "Name" : "M8" } m8 } export enum HoleStartStyle { annotation { "Name" : "Start from part" } PART, annotation { "Name" : "Start from sketch plane" } SKETCH, annotation { "Name" : "Start from selected plane" } PLANE } export enum HoleEndStyleV2 { annotation { "Name" : "Blind" } BLIND, annotation { "Name" : "Up to next" } UP_TO_NEXT, annotation { "Name" : "Up to entity" } UP_TO_ENTITY, annotation { "Name" : "Through all" } THROUGH } const MY_HEX_SIZES = { MyHexSizes.m3 : 6.12 * millimeter, MyHexSizes.m4 : 7.275 * millimeter, MyHexSizes.m5 : 8.429 * millimeter, MyHexSizes.m6 : 10.739 * millimeter, MyHexSizes.m8 : 13.048 * millimeter, }; annotation { "Feature Type Name" : "AEHex Cutout", "Feature Type Description" : "" } export const AEHexCutout = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Start plane", "Filter" : EntityType.FACE, "UIHint" : UIHint.INITIAL_FOCUS, "MaxNumberOfPicks" : 1 } definition.startPlane is Query; annotation { "Name" : "Sketch points to place hexserts", "Filter" : EntityType.VERTEX && SketchObject.YES && ModifiableEntityOnly.YES, "UIHint" : UIHint.INITIAL_FOCUS } definition.locations is Query; annotation { "Name" : "Thread size", "UIHint" : UIHint.SHOW_LABEL } definition.hexsize is MyHexSizes; annotation { "Name" : "Opposite direction", "UIHint" : UIHint.OPPOSITE_DIRECTION } definition.oppositeDirection is boolean; } { const locations = reduceLocations(context, definition.locations); const world_plane = evFaceTangentPlane(context, { "face" : definition.startPlane, "parameter" : vector(0.5, 0.5) }); const world_css = planeToCSys(world_plane); /* println(world_css.origin); println(world_css.zAxis); println(size(locations)); */ for (var i = 0; i < size(locations); i += 1) { var this_point = evVertexPoint(context, { "vertex" : locations[i] }); println("Point " ~ i ~ ":" ~ this_point); var this_css = coordSystem(this_point, world_css.xAxis, world_css.zAxis); var this_mate = opMateConnector(context, id + i + "mateConnector1", { "coordSystem" : this_css, "owner" : qOwnerBody(definition.startPlane) }); var this_sketch = newSketchOnPlane(context, id + i + "sketch1", { "sketchPlane" : plane(this_css.origin, this_css.zAxis), "disableImprinting" : true }); skRegularPolygon(this_sketch, "polygon1", { "center" : vector(0, 0) * millimeter, "firstVertex" : vector(0 * millimeter, MY_HEX_SIZES[definition.hexsize] / 2), "sides" : 6 }); skSolve(this_sketch); var regions = qSketchRegion(id + i + "sketch1", false); var largestRegion = makeRobustQuery(context, qLargest(regions)); //this will stop evaluating the areas of the regions in queries after. opExtrude(context, id + i + "extrude1", { "entities" : largestRegion, "direction" : evOwnerSketchPlane(context, { "entity" : largestRegion }).normal * (-1), "endBound" : BoundingType.UP_TO_NEXT }); opDeleteBodies(context, id + i + "deleteMate", { "entities" : qCreatedBy(id + i + "mateConnector1") }); opDeleteBodies(context, id + i + "deleteSketches", { "entities" : qCreatedBy(id + i + "sketch1") }); booleanBodies(context, id + i + "boolean1", { "targets" : qOwnerBody(definition.startPlane), "tools" : qCreatedBy(id + i + "extrude1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION }); //println(i); } }); function reduceLocations(context is Context, rawLocationQuery is Query) returns array { if (isAtVersionOrLater(context, FeatureScriptVersionNumber.V1283_HOLE_REDUCE)) { return clusterVertexQueries(context, rawLocationQuery); } } export function clusterVertexQueries(context is Context, selected is Query) returns array { var perFeature = {}; for (var tId in evaluateQuery(context, selected)) { var operationId = lastModifyingOperationId(context, tId); if (perFeature[operationId] == undefined) { perFeature[operationId] = []; } perFeature[operationId] = append(perFeature[operationId], tId); } var clusterQueries = []; for (var entry in perFeature) { var nPoints = size(entry.value); if (nPoints == 1) { clusterQueries = append(clusterQueries, entry.value[0]); } else { var points = makeArray(nPoints); for (var i = 0; i < nPoints; i = i + 1) { points[i] = evVertexPoint(context, { 'vertex' : entry.value[i] }); } var clusters = clusterPoints(points, TOLERANCE.zeroLength * meter); for (var cluster in clusters) { clusterQueries = append(clusterQueries, entry.value[cluster[0]]); } } } return evaluateQuery(context, qIntersection([selected, qUnion(clusterQueries)])); }
Answers
have you tried this sequence of operations manually?
does the extrude work? (debug the extruded bodies and comment out the boolean for testeing)
perhaps there's something with the extrude (e.g. up to next) that's not compatible with sheet metal…
can you share your document for more in context help?
Hi,
yes, when commenting out the boolean operation, the script works fine. I have used this booleanBodies operation in another Featurescript which where it works accordingly on sheet metal parts and normal parts.
https://advancedengineering.onshape.com/documents/3039acf6903a970db2352773/w/bb2c092a16326cd528d17d82/e/3d424a95f78a4c931755d22e?renderMode=0&uiState=67bed90aae06806e16843f6e