C#ATIA

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

亀2

こちらの続きです。
亀1 - C#ATIA

早速作ってみました。

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import math

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
        root :adsk.fusion.Component = des.rootComponent

        PNT3D = adsk.core.Point3D
        pnts = []
        a = 2
        for i in range(0, 100):
            theta = math.radians(unitDeg) * i
            r = a * theta
            x = r * math.cos(theta)
            y = r * math.sin(theta)

            pnts.append(PNT3D.create(x,y,0))

        skt = root.sketches.add(root.xYConstructionPlane)
        skt.arePointsShown = False

        drawPolygonSpirals(pnts, skt)

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

def drawPolygonSpirals(
    pnts :list,
    skt :adsk.fusion.Sketch):

    skt.isComputeDeferred = True
    lines : adsk.fusion.SketchLines = skt.sketchCurves.sketchLines

    for p1, p2 in zip(pnts,pnts[1:]):
        lines.addByTwoPoints(p1, p2) 

    skt.isComputeDeferred = False

実行結果はこちら!
f:id:kandennti:20210630123918p:plain

色々足りないのですが、まぁ出だしは良いでしょう。
・・・業務が忙しいと、別の事をしたくなる性格何とかならないかなぁ。