Skip to content

Commit

Permalink
integrated simple updater sample from https://forums.autodesk.com/t5/…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytammik committed Nov 25, 2020
1 parent 0d872b1 commit 153a55b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
101 changes: 100 additions & 1 deletion BuildingCoder/BuildingCoder/CmdElevationWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
Expand Down Expand Up @@ -250,4 +250,103 @@ ElementCategoryFilter f
}
}
#endregion // ElevationWatcher using DMU updater

#region Simple Updater Sample
// From https://forums.autodesk.com/t5/revit-api-forum/iupdater-simple-example-needed/m-p/9893248
[Transaction( TransactionMode.Manual )]
class CmdSimpleUpdaterExample : IExternalCommand
{
class SimpleUpdater : IUpdater
{
const string Id = "d42d28af-d2cd-4f07-8873-e7cfb61903d8";

UpdaterId _updater_id { get; set; }

public SimpleUpdater(
Document doc,
AddInId addInId )
{
_updater_id = new UpdaterId(
addInId, new Guid( Id ) );

RegisterUpdater( doc );
RegisterTriggers();
}

public void RegisterUpdater( Document doc )
{
if( UpdaterRegistry.IsUpdaterRegistered(
_updater_id, doc ) )
{
UpdaterRegistry.RemoveAllTriggers( _updater_id );
UpdaterRegistry.UnregisterUpdater( _updater_id, doc );
}
UpdaterRegistry.RegisterUpdater( this, doc );
}

public void RegisterTriggers()
{
if( null != _updater_id
&& UpdaterRegistry.IsUpdaterRegistered(
_updater_id ) )
{
UpdaterRegistry.RemoveAllTriggers( _updater_id );
UpdaterRegistry.AddTrigger( _updater_id,
new ElementCategoryFilter( BuiltInCategory.OST_Walls ),
Element.GetChangeTypeAny() );
}
}

public void Execute( UpdaterData data )
{
Document doc = data.GetDocument();

ICollection<ElementId> ids
= data.GetModifiedElementIds();

IEnumerable<string> names
= ids.Select<ElementId, string>(
id => doc.GetElement( id ).Name );

TaskDialog.Show( "Simple Updater",
string.Join<string>( ",", names ) );
}

public string GetAdditionalInformation()
{
return "NA";
}

public ChangePriority GetChangePriority()
{
return ChangePriority.MEPFixtures;
}

public UpdaterId GetUpdaterId()
{
return _updater_id;
}

public string GetUpdaterName()
{
return "SimpleUpdater";
}
}

public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements )
{
UIApplication uiapp = commandData.Application;
Document doc = uiapp.ActiveUIDocument.Document;
AddInId addInId = uiapp.ActiveAddInId;

SimpleUpdater su = new SimpleUpdater( doc, addInId );

return Result.Succeeded;
}
}
#endregion // Simple Updater Sample

}
5 changes: 3 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
// 2020-10-27 2021.0.150.7 implemented GetLevelFor for https://thebuildingcoder.typepad.com/blog/2019/03/assigning-a-level-to-an-element-missing-it.html#comment-5127272889
// 2020-11-09 2021.0.150.8 implemented IsLessOrEqual and improved GetLevelFor
// 2020-11-10 2021.0.150.9 implemented ListForgeTypeIds
// 2020-11-25 2021.0.150.10 integrated simple updater sample from https://forums.autodesk.com/t5/revit-api-forum/iupdater-simple-example-needed/m-p/9893248
//
[assembly: AssemblyVersion( "2021.0.150.9" )]
[assembly: AssemblyFileVersion( "2021.0.150.9" )]
[assembly: AssemblyVersion( "2021.0.150.10" )]
[assembly: AssemblyFileVersion( "2021.0.150.10" )]

0 comments on commit 153a55b

Please sign in to comment.