1、Taskdialog是一个Revit风格的简单对话框,可用于显示信息和接收来自用户的简单输入。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
namespace HelloRevit
{
/// <summary>
/// Demonstrate how a basic ExternalCommand can be added to the Revit user interface.
/// And demonstrate how to create a Revit style dialog.
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
public class Command : IExternalCommand
{
#region IExternalCommand Members
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
// NOTES: Anything can be done in this method, such as create a message box,
// a task dialog or fetch some information from revit and so on.
// We mainly use the task dialog for example.
// Get the application and document from external command data.
UIApplication uIApplication = commandData.Application;
Application app = commandData.Application.Application;
UIDocument uIDocument = commandData.Application.ActiveUIDocument;
Document activeDoc = commandData.Application.ActiveUIDocument.Document;
#region Task Dialog Sample
// Study how to create a revit style dialog using task dialog API by following
// code snippet.
// Creates a Revit task dialog to communicate information to the interactive user.
TaskDialog mainDialog = new TaskDialog("Hello, Revit!--这是Titil");
mainDialog.MainInstruction = "Hello, Revit!--这是MainInstruction";
mainDialog.MainContent =
"--这是MainContent--,This sample shows how a basic ExternalCommand can be added to the Revit user interface."
+ " It uses a Revit task dialog to communicate information to the interactive user.\n"
+ "The command links below open additional task dialogs with more information.";
// Add commmandLink 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 =
"<a href=\"http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975 \">"
+ "--这是FooterText--Click here for the Revit API Developer Center</a>";
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);
}
#endregion
return Autodesk.Revit.UI.Result.Succeeded;
}
#endregion
}
}