C#ATIA

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

選択せずにOccurrenceのPathsを取得

この辺で行っている処理なのですが、

ブラウザツリーのフォルダを表示/非表示する2 - C#ATIA

OccurrenceのPaths取得するのに、APIでOccurrenceを選択して
取得していたのですが、巨大Assyの場合は避けたい気持ちが
あったのですが、選択しない方法がイマイチ分かっていません
でした。

こんな感じで大丈夫なのが分かりました。

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
import json

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

        # selections.add 出来る paths を出力
        paths = getAllOccPaths()
        app.log(f'{paths}')

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

def getAllOccPaths() -> list:
    app: adsk.core.Application = adsk.core.Application.get()

    def getAllOccIds() -> list:
        app: adsk.core.Application = adsk.core.Application.get()
        res = app.executeTextCommand(u'PEntity.Properties ComponentInstancesRoot')
        compInstancesProps = json.loads(res)

        ids = []
        for info in compInstancesProps["rooted"]:
            id = info["entityId"]
            if id < 0:
                continue
            ids.append(id)

        return ids

    def getOccFullPaths(id: int):
        app: adsk.core.Application = adsk.core.Application.get()
        entId = id
        stackIds = [id]
        while True:
            pass
            prop = getPorpsKey(str(entId), "rParent")
            if not 'entityId' in prop:
                break
            entId = prop['entityId']
            if entId < 0:
                break
            stackIds.append(entId)

        return ':'.join([str(id) for id in stackIds[::-1]])

    # *************
    occIds = getAllOccIds()
    pathsLst = [getOccFullPaths(id) for id in occIds]
    pathsLst.append(
        str(
            app.executeTextCommand(u'PEntity.ID rootInstance')
        )
    )
    return pathsLst

後は、選択せずにプロパティを切り替えたいのですが、
ムリかな・・・。

絶対に他人には分からないお話です。スイマセン。
そして一か月後の自分にもわからないお話です。