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

        msg: str = 'Select Edge'
        selFilter: str = 'Edges'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        edge: adsk.fusion.BRepEdge = sel.entity

        comp: adsk.fusion.Component = edge.body.parentComponent

        valueIpts = [
            adsk.core.ValueInput.createByReal(0),
            adsk.core.ValueInput.createByReal(0.5),
            adsk.core.ValueInput.createByReal(1),
        ]

        constPlanes: adsk.fusion.ConstructionPlanes = comp.constructionPlanes
        for valueIpt in valueIpts:
            planeIpt: adsk.fusion.ConstructionPlaneInput = constPlanes.createInput()
            planeIpt.setByDistanceOnPath(edge, valueIpt)
            constPlanes.add(planeIpt)


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


def selectEnt(
        msg: str,
        filterStr: str) -> adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None