@corijn .
Changed to use the getPrincipalAxes method to create a Minimal Box.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-E05D2232-BCD2-4588-8C1A-9FC766AAFA41
# Fusion360API Python script
import adsk.core, adsk.fusion, traceback
def run(context):
ui = adsk.core.UserInterface.cast(None)
try:
app :adsk.fusion.Application = adsk.core.Application.get()
ui = app.userInterface
des :adsk.fusion.Design = app.activeProduct
# select body
msg :str = 'Select Body'
selFiltter :str = 'Bodies'
sel :adsk.core.Selection = selectEnt(msg ,selFiltter)
if not sel: return
# get OrientedBoundingBox3D
body = sel.entity
bBox :adsk.core.OrientedBoundingBox3D = getBoundingBox(body)
# Confirmation
initBoundingBox(body, bBox)
# show info
unitsMgr = des.unitsManager
defLenUnit = unitsMgr.defaultLengthUnits
covUnit = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)
ui.messageBox('{}\nlength:{:.3f}{}\nwidth:{:.3f}{}\nheight:{:.3f}{}'.format(
body.name,
covUnit * bBox.length, defLenUnit,
covUnit * bBox.width, defLenUnit,
covUnit * bBox.height, defLenUnit,
))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def getBoundingBox(
body :adsk.fusion.BRepBody) -> adsk.core.OrientedBoundingBox3D:
# get vecter3D
prop :adsk.fusion.PhysicalProperties = body.physicalProperties
_, xAxis, yAxis, _ = prop.getPrincipalAxes()
# get MeasureManager
app :adsk.fusion.Application = adsk.core.Application.get()
measMgr :adsk.core.MeasureManager = app.measureManager
return measMgr.getOrientedBoundingBox(body, yAxis, xAxis)
def selectEnt(
msg :str,
filtterStr :str) -> adsk.core.Selection :
try:
app = adsk.core.Application.get()
ui = app.userInterface
sel = ui.selectEntity(msg, filtterStr)
return sel
except:
return None
def initBoundingBox(
body :adsk.fusion.BRepBody,
bBox :adsk.core.OrientedBoundingBox3D):
# brepBody
tmpMgr :adsk.fusion.TemporaryBRepManager = adsk.fusion.TemporaryBRepManager.get()
bRepBox = tmpMgr.createBox(bBox)
# get comp
app :adsk.fusion.Application = adsk.core.Application.get()
des :adsk.fusion.Design = app.activeProduct
root :adsk.fusion.Component = des.rootComponent
# add body
box = adsk.fusion.BRepBody.cast(None)
if des.designType == adsk.fusion.DesignTypes.DirectDesignType:
box = root.bRepBodies.add(bRepBox)
box.opacity = 0.5
else:
baseFeatures = root.features.baseFeatures
baseFeature = baseFeatures.add()
baseFeature.startEdit()
try:
box = root.bRepBodies.add(bRepBox, baseFeature)
box.opacity = 0.5
except:
pass
finally:
baseFeature.finishEdit()
The initBoundingBox function is for confirmation, so please delete it if you do not need it.