How to join/knit adjacent surface bodies? joinSurfaceBodies?
mahir
Member, Developers Posts: 1,324 ✭✭✭✭✭
I'm trying to work around the shortcomings of using opBoolean to intersect multiple surfaces. To do this I've enlisted the help of opSplit, which has its own restrictions. Specifically, the target query can only contain one body. This is problematic when trying to find the intersection of a group of tool faces/bodies with a group of target faces/bodies. Instead of performing multiple splits on each combination/permutation of tool body vs target body, the easiest fix would be to combine all tools into one cohesive body, all targets into another body, and perform a split using those two surface bodies. Problem is I haven't found a way to implement this.
OS has an internal joinSurfaceBodies() function, but it's not exactly intuitive how to generate all the required inputs (matches, reconstructOp, etc). I hope this makes sense. I'd link to an example, but since it's not working it wouldn't be much help.
OS has an internal joinSurfaceBodies() function, but it's not exactly intuitive how to generate all the required inputs (matches, reconstructOp, etc). I hope this makes sense. I'd link to an example, but since it's not working it wouldn't be much help.
Tagged:
1
Best Answers
-
@mahir
I have a custom feature that will compute the inputs for opBoolean: https://cad.onshape.com/documents/84d939daceef6a928b8abcba5 -
For those that read this later, @mbartlett21's featurescript allows opBoolean to successfully perform a Union on adjacent surface bodies by computing matching edges with the following function. It's an elegant implementation and simpler than OS's createMatchesForSurfaceJoin().
function computeMatches(context is Context, id is Id, tools is Query) returns array { var partsToDelete = qNothing(); var returnArray = []; const allParts = evaluateQuery(context, tools); for (var i = 0; i < size(allParts); i += 1) { for (var j = i; j < size(allParts); j += 1) { if (i == j) { continue; } var matchMap = {}; var parts = qUnion([allParts[i], allParts[j]]); const booleanId = id + ("boolean" ~ i ~ "_" ~ j); try silent { opBoolean(context, booleanId, { "tools" : parts, "operationType" : BooleanOperationType.INTERSECTION, "keepTools" : true, "allowSheets" : true, "eraseImprintedEdges" : false }); partsToDelete = qUnion([partsToDelete, qCreatedBy(booleanId, EntityType.BODY)]); var intersections = evaluateQuery(context, qCreatedBy(booleanId)); for (var intersection in intersections) { // debug(context, qCreatedBy(booleanId)); var allVertices = evaluateQuery(context, qOwnedByBody(intersection, EntityType.VERTEX)); for (var k = 0; k < size(allVertices); k += 1) { for (var l = k; l < size(allVertices); l += 1) { if (k == l) { continue; } var vertex0 = evVertexPoint(context, { "vertex" : allVertices[k] }); var vertex1 = evVertexPoint(context, { "vertex" : allVertices[l] }); var matchingEdges = qContainsPoint(qContainsPoint(qOwnedByBody(parts, EntityType.EDGE), vertex0), vertex1); if (size(evaluateQuery(context, matchingEdges)) == 2) { matchMap = { "topology" : matchingEdges, "matchType" : TopologyMatchType.COINCIDENT }; returnArray = append(returnArray, matchMap); } } } } } } }
0 -
@mahirmahir said:For those that read this later, @mbartlett21's featurescript allows opBoolean to successfully perform a Union on adjacent surface bodies by computing matching edges with the following function. It's an elegant implementation and simpler than OS's createMatchesForSurfaceJoin().function computeMatches(context is Context, id is Id, tools is Query) returns array { var partsToDelete = qNothing(); var returnArray = []; const allParts = evaluateQuery(context, tools); for (var i = 0; i < size(allParts); i += 1) { for (var j = i; j < size(allParts); j += 1) { if (i == j) { continue; } var matchMap = {}; var parts = qUnion([allParts[i], allParts[j]]); const booleanId = id + ("boolean" ~ i ~ "_" ~ j); try silent { opBoolean(context, booleanId, { "tools" : parts, "operationType" : BooleanOperationType.INTERSECTION, "keepTools" : true, "allowSheets" : true, "eraseImprintedEdges" : false }); partsToDelete = qUnion([partsToDelete, qCreatedBy(booleanId, EntityType.BODY)]); var intersections = evaluateQuery(context, qCreatedBy(booleanId)); for (var intersection in intersections) { // debug(context, qCreatedBy(booleanId)); var allVertices = evaluateQuery(context, qOwnedByBody(intersection, EntityType.VERTEX)); for (var k = 0; k < size(allVertices); k += 1) { for (var l = k; l < size(allVertices); l += 1) { if (k == l) { continue; } var vertex0 = evVertexPoint(context, { "vertex" : allVertices[k] }); var vertex1 = evVertexPoint(context, { "vertex" : allVertices[l] }); var matchingEdges = qContainsPoint(qContainsPoint(qOwnedByBody(parts, EntityType.EDGE), vertex0), vertex1); if (size(evaluateQuery(context, matchingEdges)) == 2) { matchMap = { "topology" : matchingEdges, "matchType" : TopologyMatchType.COINCIDENT }; returnArray = append(returnArray, matchMap); } } } } } } } <b>try silent { opDeleteBodies(context, id + "deleteMatchBodies", { "entities" : partsToDelete }); } return returnArray; }</b>
You forgot the little bit on the end
5
Answers
-
@mahir
I have a custom feature that will compute the inputs for opBoolean: https://cad.onshape.com/documents/84d939daceef6a928b8abcba5 -
Thanks, @mbartlett21. I should be able to dissect your FS for what I need.
0 -
For those that read this later, @mbartlett21's featurescript allows opBoolean to successfully perform a Union on adjacent surface bodies by computing matching edges with the following function. It's an elegant implementation and simpler than OS's createMatchesForSurfaceJoin().
function computeMatches(context is Context, id is Id, tools is Query) returns array { var partsToDelete = qNothing(); var returnArray = []; const allParts = evaluateQuery(context, tools); for (var i = 0; i < size(allParts); i += 1) { for (var j = i; j < size(allParts); j += 1) { if (i == j) { continue; } var matchMap = {}; var parts = qUnion([allParts[i], allParts[j]]); const booleanId = id + ("boolean" ~ i ~ "_" ~ j); try silent { opBoolean(context, booleanId, { "tools" : parts, "operationType" : BooleanOperationType.INTERSECTION, "keepTools" : true, "allowSheets" : true, "eraseImprintedEdges" : false }); partsToDelete = qUnion([partsToDelete, qCreatedBy(booleanId, EntityType.BODY)]); var intersections = evaluateQuery(context, qCreatedBy(booleanId)); for (var intersection in intersections) { // debug(context, qCreatedBy(booleanId)); var allVertices = evaluateQuery(context, qOwnedByBody(intersection, EntityType.VERTEX)); for (var k = 0; k < size(allVertices); k += 1) { for (var l = k; l < size(allVertices); l += 1) { if (k == l) { continue; } var vertex0 = evVertexPoint(context, { "vertex" : allVertices[k] }); var vertex1 = evVertexPoint(context, { "vertex" : allVertices[l] }); var matchingEdges = qContainsPoint(qContainsPoint(qOwnedByBody(parts, EntityType.EDGE), vertex0), vertex1); if (size(evaluateQuery(context, matchingEdges)) == 2) { matchMap = { "topology" : matchingEdges, "matchType" : TopologyMatchType.COINCIDENT }; returnArray = append(returnArray, matchMap); } } } } } } }
0 -
@mahirmahir said:For those that read this later, @mbartlett21's featurescript allows opBoolean to successfully perform a Union on adjacent surface bodies by computing matching edges with the following function. It's an elegant implementation and simpler than OS's createMatchesForSurfaceJoin().function computeMatches(context is Context, id is Id, tools is Query) returns array { var partsToDelete = qNothing(); var returnArray = []; const allParts = evaluateQuery(context, tools); for (var i = 0; i < size(allParts); i += 1) { for (var j = i; j < size(allParts); j += 1) { if (i == j) { continue; } var matchMap = {}; var parts = qUnion([allParts[i], allParts[j]]); const booleanId = id + ("boolean" ~ i ~ "_" ~ j); try silent { opBoolean(context, booleanId, { "tools" : parts, "operationType" : BooleanOperationType.INTERSECTION, "keepTools" : true, "allowSheets" : true, "eraseImprintedEdges" : false }); partsToDelete = qUnion([partsToDelete, qCreatedBy(booleanId, EntityType.BODY)]); var intersections = evaluateQuery(context, qCreatedBy(booleanId)); for (var intersection in intersections) { // debug(context, qCreatedBy(booleanId)); var allVertices = evaluateQuery(context, qOwnedByBody(intersection, EntityType.VERTEX)); for (var k = 0; k < size(allVertices); k += 1) { for (var l = k; l < size(allVertices); l += 1) { if (k == l) { continue; } var vertex0 = evVertexPoint(context, { "vertex" : allVertices[k] }); var vertex1 = evVertexPoint(context, { "vertex" : allVertices[l] }); var matchingEdges = qContainsPoint(qContainsPoint(qOwnedByBody(parts, EntityType.EDGE), vertex0), vertex1); if (size(evaluateQuery(context, matchingEdges)) == 2) { matchMap = { "topology" : matchingEdges, "matchType" : TopologyMatchType.COINCIDENT }; returnArray = append(returnArray, matchMap); } } } } } } } <b>try silent { opDeleteBodies(context, id + "deleteMatchBodies", { "entities" : partsToDelete }); } return returnArray; }</b>
You forgot the little bit on the end
5 -
Lost track of the }'s
0 -
@mahir
It now finds even more matches0
