Message 1 of 11
Not applicable
10-09-2019
10:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all - I'm new to the API and C# and would really appreciate some help. I'm trying to use IUpdater in a macro that automatically starts when a project opens. Is this possible?
So far, I used Macro Manager / Create to set up some boilerplate. Then I pasted in Autodesk's WallUpdater example code (link) into 'public partial class ThisDocument'.
I figured out how to run code on project startup by calling it from the boilerplate's 'private void Module_Startup'. But I haven't had any luck calling WallUpdater.
My code is below. Any ideas or sample code would be highly appreciated. Thanks
Dave
using System;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System.Collections.Generic;
using System.Linq;
namespace test
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("redacted")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
TaskDialog.Show("hello","this pops up when you open the project");
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public class WallUpdaterApplication : Autodesk.Revit.UI.IExternalApplication
{
public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application)
{
// Register wall updater with Revit
WallUpdater updater = new WallUpdater(application.ActiveAddInId);
UpdaterRegistry.RegisterUpdater(updater);
// Change Scope = any Wall element
ElementClassFilter wallFilter = new ElementClassFilter(typeof(Wall));
// Change type = element addition
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), wallFilter, Element.GetChangeTypeElementAddition());
return Result.Succeeded;
}
public Result OnShutdown(Autodesk.Revit.UI.UIControlledApplication application)
{
WallUpdater updater = new WallUpdater(application.ActiveAddInId);
UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
return Result.Succeeded;
}
}
public class WallUpdater : IUpdater
{
static AddInId m_appId;
static UpdaterId m_updaterId;
WallType m_wallType = null;
// constructor takes the AddInId for the add-in associated with this updater
public WallUpdater(AddInId id)
{
m_appId = id;
m_updaterId = new UpdaterId(m_appId, new Guid("FBFBF6B2-4C06-42d4-97C1-D1B4EB593EFF"));
}
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
// Cache the wall type
if (m_wallType == null)
{
TaskDialog.Show("hello", "world");
}
if (m_wallType != null)
{
TaskDialog.Show("hello", "world");
}
}
public string GetAdditionalInformation()
{
return "Wall type updater example: updates all newly created walls to a special wall";
}
public ChangePriority GetChangePriority()
{
return ChangePriority.FloorsRoofsStructuralWalls;
}
public UpdaterId GetUpdaterId()
{
return m_updaterId;
}
public string GetUpdaterName()
{
return "Wall Type Updater";
}
}
}
}
Solved! Go to Solution.