C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)※記載されている内容は個人の意見であり、所属する団体等を代表する意見では御座いません・・・・よ!

六角形の中心を拘束する

最近、イヤ今年は忙しく "あれもやらなきゃ" ”これもやらなきゃ" と思いながら
すごしているのですが、最終的にはどうでも良いことをやってしまうのが人間ですよね?

こちらもそうです。
https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-constrain-centre-of-a-polygon/m-p/14217580/highlight/true#M22979

スケッチで六角形を描いた中心点が拘束出来ない との事です。
処理的にみると、スケッチの点を先に拘束していてその点を中心とした六角形を描いていました。
個人的にもそれで間違っていないと思います、FusionAPI的に。

最初に試した際には行き詰ったのですが、あちらに記載したようにスケッチの点の数を出力して
気が付きました。増えた最初の点か最後の点が中心だろうと。

あちらのコードは質問者の方のものをそのまま使ったのですが、中心点用のスケッチの点は
作成する必要は無いですね。こんな感じです。(型ヒントは入れるべき)

# Fusion360API Python script

import traceback

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


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

        des.designType = fusion.DesignTypes.DirectDesignType

        constPoints: fusion.ConstructionPoints = root.constructionPoints
        pointIpt: fusion.ConstructionPointInput = constPoints.createInput()
        pointIpt.setByPoint(core.Point3D.create(1, 2, 3))
        points = [constPoints.add(pointIpt)]

        des.designType = fusion.DesignTypes.ParametricDesignType

        sketchPlane: fusion.ConstructionPlane = root.xYConstructionPlane
        sketches: fusion.Sketches = root.sketches

        rotationAngle: float = 0
        halfHoleSize: float = 1
        holeSize: float = 1.5
        # -----------

        hexSketch: fusion.Sketch = sketches.addWithoutEdges(sketchPlane)

        projectedPoints: fusion.SketchEntityList = hexSketch.project2(points, True)
        constraints: fusion.GeometricConstraints = hexSketch.geometricConstraints

        print(f"Before: {hexSketch.sketchPoints.count}")

        firstPolylines = hexSketch.sketchCurves.sketchLines.addScribedPolygon(
            core.Point3D.create(0, 0, 0), 6, rotationAngle, halfHoleSize, False
        )

        print(f"After: {hexSketch.sketchPoints.count}")

        _: fusion.CoincidentConstraint = constraints.addCoincident(
            hexSketch.sketchPoints[-1], projectedPoints[0]
        )

        firstParraLine: fusion.SketchLine = firstPolylines[0]
        oppLine: fusion.SketchLine = firstPolylines[3]
        hexDim: fusion.SketchOffsetDimension = (
            hexSketch.sketchDimensions.addOffsetDimension(
                firstParraLine, oppLine, firstParraLine.startSketchPoint.worldGeometry
            )
        )
        hexDim.value = holeSize

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

珍しく、AIパワーなしで書きましたよ。