TaskDialog は単純な Windows メッセージボックスの代わりとなる Revit-スタイルのメッセージボックスです。これを使用して情報を表示したり、ユーザからの単純な入力を受け取ることができます。これには標準の順序で配列されているコントロールの共通セットがあり、Revit の他の部分と見た目と操作性に一貫性を持たせています。
図 19: Revit-スタイル タスク ダイアログ
タスク ダイアログを作成してユーザに表示するには、2 つの方法があります。最初のオプションは、TaskDialog を構築し、プロパティを個別に設定し、インスタンス メソッドの Show()を使用してこれをユーザに表示します。2 番目は、静的な Show()メソッドのいずれかを使用して、ダイアログを 1 ステップで構築、表示します。静的なメソッドを使用する場合は、オプションのサブセットのみを指定できます。
「タスク ダイアログ」(「API ユーザ インタフェース ガイドライン」のセクション)を参照してください。
次の例では、上記のタスクの作成、表示方法を示します。
コード領域 3-27: Revit-スタイル タスク ダイアログ |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]
class TaskDialogExample : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
// Get the application and document from external command data.
Application app = commandData.Application.Application;
Document activeDoc = commandData.Application.ActiveUIDocument.Document;
// Creates a Revit task dialog to communicate information to the user.
TaskDialog mainDialog = new TaskDialog("Hello, Revit!");
mainDialog.MainInstruction = "Hello, Revit!";
mainDialog.MainContent =
"This sample shows how to use a Revit task dialog to communicate with the user."
+ "The command links below open additional task dialogs with more information.";
// Add commmandLink options to task dialog
mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
"View information about the Revit installation");
mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
"View information about the active document");
// Set common buttons and default button. If no CommonButton or CommandLink is added,
// task dialog will show a Close button by default
mainDialog.CommonButtons = TaskDialogCommonButtons.Close;
mainDialog.DefaultButton = TaskDialogResult.Close;
// Set footer text. Footer text is usually used to link to the help document.
mainDialog.FooterText =
"" + "Click here for the Revit API Developer Center";
TaskDialogResult tResult = mainDialog.Show();
// If the user clicks the first command link, a simple Task Dialog
// with only a Close button shows information about the Revit installation.
if (TaskDialogResult.CommandLink1 == tResult)
{
TaskDialog dialog_CommandLink1 = new TaskDialog("Revit Build Information");
dialog_CommandLink1.MainInstruction =
"Revit Version Name is: " + app.VersionName + "\n"
+ "Revit Version Number is: " + app.VersionNumber + "\n"
+ "Revit Version Build is: " + app.VersionBuild;
dialog_CommandLink1.Show();
}
// If the user clicks the second command link, a simple Task Dialog
// created by static method shows information about the active document
else if (TaskDialogResult.CommandLink2 == tResult)
{
TaskDialog.Show("Active Document Information",
"Active document: " + activeDoc.Title + "\n"
+ "Active view name: " + activeDoc.ActiveView.Name);
}
return Autodesk.Revit.UI.Result.Succeeded;
}
}
|