Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
To create an OrientedBoundingBox3D from multiple faces, I merge them using the script below.
See the attached script as file and as text.
Most of the time this works very well, but with more complex (many) faces I get an error message.
If I manually stitch the faces together, it works without any issues (see video).
Does anyone have an idea how to successfully combine the faces for the OrientedBoundingBox3D?
Best regards
Maurizio
import traceback
import adsk.core
import adsk.fusion
# import adsk.cam
# Initialize the global variables for the Application and UserInterface objects.
app = adsk.core.Application.get()
ui = app.userInterface
def run(_context: str):
"""This function is called by Fusion when the script is run."""
try:
faces = []
for i in range(ui.activeSelections.count):
sel = ui.activeSelections.item(i)
if isinstance(sel.entity, adsk.fusion.BRepFace):
faces.append(sel.entity)
if len(faces) > 0:
create_union_body(faces)
except:
app.log(f'Failed:\n{traceback.format_exc()}')
# Create a temporary UnionBody
def create_union_body(faces: list) -> adsk.fusion.BRepBody:
if len(faces) < 1:
return None
tmpMgr: adsk.fusion.TemporaryBRepManager = adsk.fusion.TemporaryBRepManager.get()
tmpBody: adsk.fusion.BRepBody = tmpMgr.copy(faces[0])
if len(faces) < 2:
return tmpBody
for face in faces[1:]:
tmpMgr.booleanOperation(
tmpBody,
tmpMgr.copy(face),
adsk.fusion.BooleanTypes.UnionBooleanType,
)
return tmpBody
Solved! Go to Solution.