C#ATIA

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

Fusion360 選択したオブジェクトのタイプを表示

やっとCATVBAのSelectElement2のような処理を行う、Fusion360APIのサンプルを
見つけました。 早速流用して開発向けのスクリプトを作成してみました。

#GetGeometryObjectType by kantoku
#fusionAPI_python
import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        try:
            while True:
                ent = ui.selectEntity("点・線・面等を選択中。中止するにはEscキーを", "Vertices,Edges,Faces")
                geo = ent.entity.geometry
                msg = "objectType : " + ent.entity.objectType + "\n"
                msg += "geometry_objectType : " + geo.objectType
                ui.messageBox(msg)
        except:         
            ui.messageBox('終了')
            return
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

スクリプト実行後入力待ち状態になるので、点・線・面等を選択すると選択したものの
オブジェクトタイプとジオメトリとしてのオブジェクトタイプを表示します。
無限ループ状態なので、Escキー入力で終了です。

以下の部分悩み中
・selectEntity時のフィルターで、オールマイティーな記述方法は無いのかな?
・selectEntity時にショートカットキー入力が受付られちゃう。殺す方法無いかな?
・オブジェクトの名前を取得する方法は無いかな?

CATIAのように記録が取れないので、苦しむような気はするけど
これをもっと育てれば、開発が楽になるはず。