Skip to content

Commit

Permalink
Update BuiltInParameterUpdater to register BuiltInParameter array.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Sep 5, 2024
1 parent efe6f79 commit 1d7aac9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.0.0] / 2024-09-05
- Test Wall updater when the curve is changed.
- Update `BuiltInParameterUpdater` to register `BuiltInParameter` array.

[vNext]: ../../compare/1.0.0...HEAD
[1.0.0]: ../../compare/1.0.0
19 changes: 12 additions & 7 deletions RevitTest.Updater/Utils/BuiltInParameterUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public ElementFilter GetElementFilter()

return new ElementCategoryFilter(BuiltInCategory.INVALID, true);
}
private void AddTriggerAllBuiltInParameter()
private void AddTriggerAllBuiltInParameter(params BuiltInParameter[] builtInParameters)
{
var elementFilter = GetElementFilter();
var changeTypes = GetChangeTypes();
var changeTypes = GetChangeTypes(builtInParameters);
foreach (var changeType in changeTypes)
{
UpdaterRegistry.AddTrigger(GetUpdaterId(), elementFilter, changeType);
Expand All @@ -96,14 +96,19 @@ private void AddTriggerAllBuiltInParameter()
UpdaterRegistry.AddTrigger(GetUpdaterId(), elementFilter, Element.GetChangeTypeAny());
}

private IEnumerable<ChangeType> GetChangeTypes()
private IEnumerable<ChangeType> GetChangeTypes(params BuiltInParameter[] builtInParameters)
{
//return new[] {
// Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)),
// Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.HOST_VOLUME_COMPUTED))
//};
var values = Enum.GetValues(typeof(BuiltInParameter)).Cast<BuiltInParameter>();
var changeTypes = values.Select(e => Element.GetChangeTypeParameter(new ElementId(e)));

if (builtInParameters.Length == 0)
{
builtInParameters = Enum.GetValues(typeof(BuiltInParameter)).Cast<BuiltInParameter>().ToArray();
}

var changeTypes = builtInParameters.Select(e => Element.GetChangeTypeParameter(new ElementId(e)));
return changeTypes;
}

Expand Down Expand Up @@ -145,13 +150,13 @@ public void Disable()
UpdaterRegistry.DisableUpdater(GetUpdaterId());
}

public void Register()
public void Register(params BuiltInParameter[] builtInParameters)
{
if (UpdaterRegistry.IsUpdaterRegistered(GetUpdaterId())) return;

UpdaterRegistry.RegisterUpdater(this, true);

AddTriggerAllBuiltInParameter();
AddTriggerAllBuiltInParameter(builtInParameters);
}

public void Unregister()
Expand Down
4 changes: 2 additions & 2 deletions RevitTest.Updater/WallUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class WallUpdaterTests : OneTimeOpenDocumentTest
public void UpdaterRegister(UIApplication uiapp)
{
this.builtInParameterUpdater = new BuiltInParameterUpdater(uiapp.ActiveAddInId);
this.builtInParameterUpdater.Register();
this.builtInParameterUpdater.Register(BuiltInParameter.CURVE_ELEM_LENGTH, BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
}

[OneTimeTearDown]
Expand Down Expand Up @@ -52,9 +52,9 @@ public void WallTests_CreateWall()
}

Assert.AreEqual(12, wall.GetLenght());
Assert.IsTrue(builtInParameterUpdater.ElementIdChangeType[wall.Id].Contains(BuiltInParameter.INVALID));

// This should contain CURVE_ELEM_LENGTH but Revit does not consider the parameter as change using 'UpdaterData.IsChangeTriggered'.
Assert.IsTrue(builtInParameterUpdater.ElementIdChangeType[wall.Id].Contains(BuiltInParameter.INVALID));
Assert.IsFalse(builtInParameterUpdater.ElementIdChangeType[wall.Id].Contains(BuiltInParameter.CURVE_ELEM_LENGTH));

using (Transaction transaction = new Transaction(document))
Expand Down

0 comments on commit 1d7aac9

Please sign in to comment.