C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

選択面のバウンダリングボックス

作っちゃったけど違うみたいなので、残しておきます。

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        # select face
        msg: str = 'Select'
        selFilter: str = 'Faces'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        selectFace: adsk.fusion.BRepFace = sel.entity

        # get OrientedBoundingBox
        measMgr: adsk.core.MeasureManager = app.measureManager
        bBox: adsk.core.OrientedBoundingBox3D = measMgr.getOrientedBoundingBox(
            selectFace,
            adsk.core.Vector3D.create(0,1,0),
            adsk.core.Vector3D.create(1,0,0)
        )

        # draw BoundingBox
        tmpMgr: adsk.fusion.TemporaryBRepManager = adsk.fusion.TemporaryBRepManager.get()
        tmpBody: adsk.fusion.BRepBody = tmpMgr.createBox(bBox)

        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent
        baseFeat: adsk.fusion.BaseFeature = None
        if des.designType == adsk.fusion.DesignTypes.ParametricDesignType:
            baseFeat = root.features.baseFeatures.add()

        bodies: adsk.fusion.BRepBodies = root.bRepBodies
        body: adsk.fusion.BRepBody = None
        if baseFeat:
            baseFeat.startEdit()
            body = bodies.add(tmpBody, baseFeat)
            body.opacity = 0.3
            baseFeat.finishEdit()
        else:
            body = bodies.add(tmpBody)
            body.opacity = 0.3

        # message
        unitMgr: adsk.core.UnitsManager = des.unitsManager
        width = unitMgr.formatInternalValue(bBox.width)
        length = unitMgr.formatInternalValue(bBox.length)
        height = unitMgr.formatInternalValue(bBox.height)

        ui.messageBox(f':{width} x {length} x {height}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))