As announced previously, Revit Addin Wizard (RevitAddinWizard) has supported Revit API 2012 additionally natively and seamlessly.
Its welcome page is the same as before. Other wizard pages have been changed a lot but the backward compatibility is perfectly maintained. The project-setting page goes first:
Version 2012 is available in the combo box now and when it is chosen the product list will be automatically refreshed to provide all properly installed Revit 2012 applications and flavors. In addition, one more edit box, Vendor ID, will show up to collect the VendorId node for the manifest file in the resultant addin project.
As talked before, Revit API 2012 only supports the Manual RegenerationOption now and provides ribbon tab creation. These are reflected in the external application setting page:
The Automatic RegenerationOption will automatically disappear when version 2012 is chosen in the previous page but the Tab name edit box show up.
The Manual RegenerationOption applies to the external command setting page as well:
The summary page will reflect the newly added options:
Do not worry about those addin project settings of version 2011. They look and work almost the same as before, and better actually, some tiny issues being fixed improved.
Here is the code automatically generated based on the settings above:
#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 RevitAddinCS1
{
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Manual)]
public class ExtApp : IExternalApplication
{
#region Cached Variables
public static UIControlledApplication _cachedUiCtrApp;
#endregion
#region IExternalApplication Members
public Result OnStartup(UIControlledApplication uiApp)
{
_cachedUiCtrApp = uiApp;
try
{
RibbonPanel ribbonPanel = CreateRibbonPanel();
//TODO: add you code below.
uiApp.ControlledApplication.DocumentChanged += AppEventHandlers1.ApplicationEvent_DocumentChanged_Handler;
uiApp.ControlledApplication.DocumentOpened += AppEventHandlers1.ApplicationEvent_DocumentOpened_Handler;
uiApp.ControlledApplication.DocumentSavedAs += AppEventHandlers1.ApplicationEvent_DocumentSavedAs_Handler;
DocEventSubscriber docEventScrscipber = new DocEventSubscriber(_cachedUiCtrApp); //Subscribe to all documents in the whole Revit session.
// Register the ElementUpdater1
ElementUpdater1 updater1 = new ElementUpdater1(uiApp.ActiveAddInId);
Autodesk.Revit.DB.UpdaterRegistry.RegisterUpdater(updater1);
Autodesk.Revit.DB.ElementCategoryFilter catFilter = new Autodesk.Revit.DB.ElementCategoryFilter(Autodesk.Revit.DB.BuiltInCategory.OST_AdaptivePoints_Planes);
Autodesk.Revit.DB.UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Autodesk.Revit.DB.Element.GetChangeTypeElementAddition());
Autodesk.Revit.DB.UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Autodesk.Revit.DB.Element.GetChangeTypeElementDeletion());
Autodesk.Revit.DB.UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Autodesk.Revit.DB.Element.GetChangeTypeGeometry());
return Result.Succeeded;
}
catch (Exception ex)
{
MessageBox.Show( ex.ToString() );
return Result.Failed;
}
}
public Result OnShutdown(UIControlledApplication uiApp)
{
try
{
//TODO: add you code below.
uiApp.ControlledApplication.DocumentChanged -= AppEventHandlers1.ApplicationEvent_DocumentChanged_Handler;
uiApp.ControlledApplication.DocumentOpened -= AppEventHandlers1.ApplicationEvent_DocumentOpened_Handler;
uiApp.ControlledApplication.DocumentSavedAs -= AppEventHandlers1.ApplicationEvent_DocumentSavedAs_Handler;
// Unregister the ElementUpdater1
UpdaterRegistry.UnregisterUpdater(new ElementUpdater1(uiApp.ActiveAddInId).GetUpdaterId());
return Result.Succeeded;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return Result.Failed;
}
}
#endregion
#region Local Methods
private RibbonPanel CreateRibbonPanel()
{
try{_cachedUiCtrApp.CreateRibbonTab("ABC");}catch{}
RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel("ABC", Guid.NewGuid().ToString());
panel.Name = "ABC_RevitAddinCS1_ExtApp";
panel.Title = "RevitAddinCS1";
////Default button:
PushButtonData pbDataExtCmd = new PushButtonData("ExtCmd", "ExtCmd", Assembly.GetExecutingAssembly().Location, "RevitAddinCS1.ExtCmd");
PushButton pbExtCmd = panel.AddItem(pbDataExtCmd) as PushButton;
pbExtCmd.ToolTip = "ExtCmd";
pbExtCmd.LargeImage = BmpImageSource("RevitAddinCS1.Resources.ExtCmd32x32.bmp");
pbExtCmd.Image = BmpImageSource("RevitAddinCS1.Resources.ExtCmd16x16.bmp");
////More buttons:
return panel;
}
private System.Windows.Media.ImageSource BmpImageSource(string embeddedPath)
{
Stream stream = this.GetType().Assembly.GetManifestResourceStream(embeddedPath);
var decoder = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
return decoder.Frames[0];
}
#endregion
}
}
Here is the manifest file content automatically generated by the wizard as well:
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Application">
<Assembly>C:\Temp\RevitAddinCS1\RevitAddinCS1\bin\Debug\RevitAddinCS1.dll</Assembly>
<FullClassName>RevitAddinCS1.ExtApp</FullClassName>
<ClientId>9b88ceb5-b5ba-4960-be5a-372ecb12af08</ClientId>
<Name>RevitAddinCS1</Name>
<VendorId>ABC</VendorId>
</AddIn>
</RevitAddIns>
Revit Addin Wizard (RevitAddinWizard) has supported Revit API 2012 additionally natively and seamlessly.
Happy New Year!
Recent Comments