暇を見ては挑戦し続けてきたのですが、ギリギリ何とか書けそうなので
アナウンスしておきたいです。
Fusion360APIでオブジェクトとしては提供されているのに、インスタンスが作成出来ない
ものの代表的なものとしてパイプフューチャーがあります。
Fusion 360 Help
".add" や "create" のようなものが無いため作る事が出来ません。
何故それを許さないのか? は謎なのですが、とにかく作る事が出来ません。
ですが、ちょっと前のUpdateでテキストコマンドがAPIで利用出来るようになったので
最低限レベルで作る事が出来ました。
こんな感じのコードです。
#Fusion360API Python script #Author-kantoku #Description-create PipeFeature sample import adsk.core, adsk.fusion, traceback _app = adsk.core.Application.cast(None) _ui = adsk.core.UserInterface.cast(None) def run(context): try: global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface des :adsk.fusion.Design = _app.activeProduct root :adsk.fusion.Component = des.rootComponent actSels :adsk.core.Selections = _ui.activeSelections # create sketch crv = initSktCircle(root) # create pipe actSels.clear() actSels.add(crv) initPipe() # create sketch crv = initSktSpline(root) # create pipe actSels.clear() actSels.add(crv) initPipe() actSels.clear() except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def initSktSpline(comp :adsk.fusion.Component): skt :adsk.fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane) poss = [[-1,2,5], [2,1,0], [0,-4,2]] pnt3D = adsk.core.Point3D objs = adsk.core.ObjectCollection.create() [objs.add(pnt3D.create(x,y,z)) for (x,y,z) in poss] crvs :adsk.fusion.SketchCurves = skt.sketchCurves crv = crvs.sketchFittedSplines.add(objs) return crv def initSktCircle(comp :adsk.fusion.Component): skt :adsk.fusion.Sketch = comp.sketches.add(comp.xYConstructionPlane) pnt3D = adsk.core.Point3D crvs :adsk.fusion.SketchCurves = skt.sketchCurves crv = crvs.sketchCircles.addByCenterRadius(pnt3D.create(-5.0,-5,0), 4.0) return crv def initPipe(): global _app txtCmds = [ u'Commands.Start PrimitivePipe', # show dialog u'Commands.SetDouble SWEEP_POP_ALONG 1.0', # input distance u'Commands.SetDouble SectionRadius 0.5', # input radius u'NuCommands.CommitCmd' # execute command ] for cmd in txtCmds: _app.executeTextCommand(cmd)
処理的には、スケッチを描きパイプ作成。再度スケッチを描きパイプを作成しています。
まぁ結果だけを見ると何てことはないんですけどね・・・。
スケッチを描く辺りはどうでも良いのですが、initPipe関数だけちょっとご説明を。
initPipe関数内ではstringのリストを順番に実行しているだけなのですが、
この文字達を見付けるのが非常に大変でした。
Commands.Start PrimitivePip
これはこの辺りで触れている CommandDefinition.execute(以下,cmdDef) に近いもので
GUI時のコマンドのダイアログを表示させています。
CommandDefinitionsオブジェクト1 - C#ATIA
ところがこちらを記載した時は気が付かなかったのですが、
cmdDefでは、スクリプトの途中で処理させても直ぐには実行してくれず、
スクリプト終了直後に実行されるため、何らかの処理の途中で使用出来ませんでした。
ところが、テキストコマンドの Commands.Start は処理の途中でも即実行してくれます。
又、"PrimitivePip" はパイプコマンドのコマンドIDです。
続いてはこちら。
Commands.SetDouble SWEEP_POP_ALONG 1.0 Commands.SetDouble SectionRadius 0.5
ダイアログが表示された際の "距離" と "断面サイズ" に値を設定しています。
困難だったのが SetDouble の第一パラメータの "target label" が一体
何を意味するのか? どうやって見付けるのか? が全くの手探りでした。
Fusion360_Small_Tools_for_Developers/TextCommands_txt_Ver2_0_8176.txt at master · kantoku-code/Fusion360_Small_Tools_for_Developers · GitHub
色々と試した結果、ダイアログ上に配置されているcommandInputのIDが
"target label" だとわかりました。
(恥ずかしながら、上手く設定出来た瞬間は声が出てしまいました・・・)
最後はこちら。
NuCommands.CommitCmd
早い話が、こちらの "OK" を押すのと同じ効果があります。
これも気が付くのに時間がかかりました。APIフォーラムでもこのボタンを
"押す方法が見つからない" との記述を見かけます。
・・・続き書けるかな?