ウォークスルー: Hello World セクションでは、アドイン アプリケーションの作成方法およびこれを Revit で呼び出す方法を学習します。また、.addin マニフェスト ファイルを作成して、外部ツールとしてアドイン アプリケーションを登録する方法も学習します。Revit でアドイン アプリケーションを実行するもう 1 つの方法として、カスタム リボンパネルから実行する方法があります。
新しいプロジェクトを作成するには、次の手順を実行します。
図 8: 参照の追加
クラス名を変更するには、次の手順を実行します。
パネルの追加プロジェクトは、Revit プロジェクトが実行されると自動的に起動されるため、Hello World とは異なります。このプロジェクトには、IExternalApplication インタフェースを使用します。IExternalApplication インタフェースには、2 つの抽象メソッド、OnStartup()および OnShutdown()が含まれます。IExternalApplication の詳細は、「アドインの統合」を参照してください。
リボン パネルに次のコードを追加します。
|
コード領域 2-5: リボン パネルを追加 |
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Windows.Media.Imaging;
class CsAddpanel : Autodesk.Revit.UI.IExternalApplication
{
public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
{
// add new ribbon panel
RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel");
//Create a push button in the ribbon panel "NewRibbonPanel"
//the add-in application "HelloWorld" will be triggered when button is pushed
PushButton pushButton = ribbonPanel.AddItem(new PushButtonData("HelloWorld",
"HelloWorld", @"D:\HelloWorld.dll", "HelloWorld.CsHelloWorld")) as PushButton;
// Set the large image shown on button
Uri uriImage = new Uri(@"D:\Sample\HelloWorld\bin\Debug\39-Globe_32x32.png");
BitmapImage largeImage = new BitmapImage(uriImage);
pushButton.LargeImage = largeImage;
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
}
|
コードの完成後、アプリケーションを作成します。[ビルド]メニューから、[ソリューションのビルド]をクリックします。ビルドの出力が出力ウィンドウに表示され、エラーなしでプロジェクトがコンパイルされたことを表します。AddPanel.dll がプロジェクト出力フォルダに配置されます。
Revit アプリケーションを起動するには、Revit に登録するマニフェスト ファイルを作成します。
|
コード領域 2-6: 外部アプリケーションの .addin ファイルを作成 |
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<RevitAddIns>
<AddIn Type="Application">
<Name>SampleApplication</Name>
<Assembly>D:\Sample\AddPanel\AddPanel\bin\Debug\AddPanel.dll</Assembly>
<AddInId>604B1052-F742-4951-8576-C261D1993107</AddInId>
<FullClassName>AddPanel.CsAddPanel</FullClassName>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
|
.addin マニフェスト ファイルの詳細は、「アドインの統合」を参照してください。
デバッグを開始するには、プロジェクトを構築し、Revit を実行します。新しいリボン パネルが NewRibbonPanel および Hello World という名前の[アドイン]タブに、パネルの唯一のボタンとして大きな地球の画像で表示されます。
図 9: Revit に新しいリボン パネルを追加
[Hello World]をクリックしてアプリケーションを実行し、次のダイアログ ボックスを表示します。
図 10: [Hello World]ダイアログ ボックス