Fusion 360 アドイン作成

Fusion 360 が更新されて、新しいバージョンが利用できるようになりました。新しいバージョンをインストールするには、Fusion 360 を起動時に自動的に表示される次のダイアログから [Update Now] ボタンをクリックするだけです。自動的に正しいバージョンをダウンロードしてインストールしてくれます。

Update notification for Fusion 360, prompting users to update to the latest version with options to 'Update Now' or 'Quit Fusion 360'.

このバージョンのもっとも大きな機能追加に、アドイン(Add-In)機能の実装があります。昨年後半には、すでにスクリプト(Script)を使った API として、JavaScript と Python をサポートし始めましたが、Script を実行する場合には、Fusion 実行中に手動で実行したい Script を直接指定する必要がありました。

今回登場した Add-In では、Fusion 360 のインストール フォルダ内にある場所から、マニフェストを利用したモジュールの自動ロードと実行が可能になる点が Script と異なります。利用できる開発言語は、現在のところ、Script と同じ JavaScript と Python の2 種類です。

新しく Add-In を作成する場合の手順は、Script と似ています。まず、画面上部にある Quick Access Toolbar の [File] メニューで [Scripts and Add-Ins] 項目を選択します。

Menu options from Autodesk Fusion 360 Ultimate software, featuring choices like New Design, Save, Export, and Scripts and Add-Ins.

[Scripts and Add-Ins] ダイアログが開いたら、[Add-Ins] タブをアクティブにして、[Creatie] ボタンをクリックすると [Create New Script or Add-In] ダイアログが表示されます。Add-In の名称や使用する開発言語を選択して、再度 [Create] ボタンをクリックします。この際、作成した Add-In を Fusion 360 の起動時に自動実行させるかを “Run on Startup” チェックボックスで指定することも出来ます。

Window for creating a new script or add-in in Autodesk Fusion 360, featuring fields for the name, description, author, version, target operating system, and folder location.

“Run on Startup” は、Add-In 作成時だけでなく、実行時にも指定することが出来ます。ただし、動作を確認するためには、Fusion 360 を再起動する必要があります。 

A computer window displaying 'Scripts and Add-Ins' with two tabs: 'My Add-Ins' showing 'Bolt Creation' and 'Remove Share menu', and 'Sample Add-Ins' with multiple items listed. There are options to create, edit, stop, and run scripts.

作成が終了すると、コードの作成/編集が可能になります。[Scripts and Add-Ins] ダイアログ上で作成した直後の Add-In 名を選択してから、[Edit] ボタンをクリックします。JavaScript か Python 別に異なる編集画面が起動します。この違いは、以前、ご紹介した Script の編集と同じ手順です。

Fusion 360 と API Tech Preview

Fusion 360 の更新と Fusion 360 Ultimate

さて、作成されたスケルトンコードには、Run と Stop の 2 つの関数が登録されています。簡単に説明してしまうと、Run がこの Add-In がロードされた際に実行される関数で、Stop は Add-In がロード解除された際に実行される関数です。”Run on Startup” を指定した場合には、Run が Fusion 360 の起動時に自動実行されるのは言うまでもありません。 

//Author-
//Description-
function run(context) {
“use strict”;
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
ui.messageBox(‘Hello addin’);
}
catch (e) {
if (ui) {
ui.messageBox(‘Failed : ‘ + (e.description ? e.description : e));
}
}
}
function stop(context) {
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
ui.messageBox(‘Stop addin’);
}
catch (e) {
if (ui) {
ui.messageBox(‘Failed : ‘ + (e.description ? e.description : e));
}
}
}

 自動実行などの特性から、ユーザ インタフェースのカスタマイズで、この機能を利用すれば有用かも知れません。

By Toshiaki Isezaki

 

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading