C#ATIA

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

平坦な面の外周をオフセットした面を作成する

こちらも上手く行かない部分テストです。


左図の歪な面があります。これを均一にオフセットした外周を持つ
面を作成します。条件はXY平面に平行な平らな面です。

延長コマンドで可能ですが、こちらもTemporaryBRepManagerで
処理したい。

# Fusion360API Python script

import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        # 各種データの取得
        body: fusion.BRepBody = root.bRepBodies[0]
        targetFace: fusion.BRepFace = body.faces[0]
        offsetValue = 1

        curves = [c.geometry for c in targetFace.edges]

        tmpMgr: fusion.TemporaryBRepManager = fusion.TemporaryBRepManager.get()
        tempWireBody, edgeMap = tmpMgr.createWireFromCurves(curves, False)
        offsetWires = []
        for wire in tempWireBody.wires:
            offsetWires.append(
                wire.offsetPlanarWire(
                    core.Vector3D.create(0,0,1),
                    offsetValue,
                    fusion.OffsetCornerTypes.CircularOffsetCornerType
                    # fusion.OffsetCornerTypes.LinearOffsetCornerType
                    # fusion.OffsetCornerTypes.ExtendedOffsetCornerType
                )
            )

        resBody: fusion.BRepBody = _get_union_body(offsetWires)
        resBody: fusion.BRepBody = tmpMgr.createFaceFromPlanarWires([resBody])


        dump_bodies([resBody])

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



def _get_union_body(
    bodyLst: list) -> fusion.BRepBody:
    '''
    ブーリアン和のボディ取得
    '''

    return _get_boolean_body(
        bodyLst,
        fusion.BooleanTypes.UnionBooleanType
    )


def _get_boolean_body(
    bodyLst: list,
    booleanType: fusion.BooleanTypes) -> fusion.BRepBody:
    '''
    ブーリアンボディ取得
    '''

    resBody: fusion.BRepBody = None
    if len(bodyLst) < 0:
        resBody = None
    elif len(bodyLst) == 1:
        resBody = bodyLst[0]
    else:
        tmpMgr: fusion.TemporaryBRepManager = fusion.TemporaryBRepManager.get()
        resBody = bodyLst.pop()
        for b in bodyLst:
            try:
                tmpMgr.booleanOperation(
                    resBody,
                    b,
                    booleanType
                )
            except:
                pass

    return resBody


def dump_bodies(bodyLst: list):
    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    baseFeat: fusion.BaseFeature = None
    if des.designType == fusion.DesignTypes.ParametricDesignType:
        baseFeat = root.features.baseFeatures.add()

    bodies: fusion.BRepBodies = root.bRepBodies
    if baseFeat:
        try:
            baseFeat.startEdit()
            [bodies.add(body, baseFeat) for body in bodyLst]
        except:
            pass
        finally:
            baseFeat.finishEdit()
    else:
        [bodies.add(body) for body in bodyLst]

で、上の画像の様に上手く行きます。
何故あっちでは上手く行かないのか・・・。