We have discussed some new features or greatly enhanced ones of Revit API 2011 earlier. Now let’s go back to something very fundamental, adding a new External Command (IExternalCommand) to Revit Addin projects with the assistance of the RevitAddinWizard.
The External Command item can be found from the Revit Addins category of the Visual C# Project Items. After the wizard has been filled in like:
A new external command (IExternalCommand) will be created and added to the current project accordingly:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
#endregion
namespace RevitAddinCS
{
[Transaction(TransactionMode.ReadOnly)]
[Regeneration(RegenerationOption.Automatic)]
public class ExtCmd3 : IExternalCommand
{
#region Cached Variables
private static ExternalCommandData _cachedCmdData;
public static UIApplication CachedUiApp
{
get
{
return _cachedCmdData.Application;
}
}
public static RvtApplication CachedApp
{
get
{
return CachedUiApp.Application;
}
}
public static RvtDocument CachedDoc
{
get
{
return CachedUiApp.ActiveUIDocument.Document;
}
}
#endregion
#region IExternalCommand Members
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
{
_cachedCmdData = cmdData;
try
{
//TODO: add your code below.
return Result.Succeeded;
}
catch (Exception ex)
{
msg = ex.ToString();
return Result.Failed;
}
}
#endregion
}
}
It is nothing new but the good thing is that the RevitAddinWizard will not only save us time but also guarantee that a valid External Command (IExternalCommand) will be there with the options that we want.
Links to some related articles:
Use RevitAddinWizard to Create IUpdater Derivatives of Revit API
Implement IFailuresPreprocessor of Revit API
Use RevitAddinWizard to Implement IFailuresPreprocessor of Revit API
Implement An IFailuresProcessor of Revit API
Use RevitAddinWizard to Implement IFailuresProcessor of Revit API
Command Availability And Revit Flavors/Categories of Revit API
Use RevitAddinWizard to Implement IExternalCommandavailability of Revit API
Implement ISelectionFilter of Revit API
Use RevitAddinWizard to Implement ISelectionFilter of Revit API
Recent Comments