Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d8d9bc59b |
@@ -0,0 +1,40 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
namespace Speckle.Connectors.Revit.Plugin;
|
||||
|
||||
public class VisibilityUpdater : IUpdater
|
||||
{
|
||||
private static UpdaterId s_updaterId;
|
||||
private readonly CategoryVisibilityTracker _tracker;
|
||||
|
||||
public VisibilityUpdater(AddInId addInId, Document doc)
|
||||
{
|
||||
s_updaterId = new UpdaterId(addInId, new Guid("B1234567-ABCD-1234-5678-9ABCDEF01234")); // Unique GUID
|
||||
_tracker = new CategoryVisibilityTracker(doc);
|
||||
}
|
||||
|
||||
public void Execute(UpdaterData data)
|
||||
{
|
||||
Document doc = data.GetDocument();
|
||||
|
||||
foreach (Category category in doc.Settings.Categories)
|
||||
{
|
||||
if (category.get_AllowsVisibilityControl(doc.ActiveView) && _tracker.HasVisibilityChanged(category))
|
||||
{
|
||||
TaskDialog.Show(
|
||||
"Visibility Changed",
|
||||
$"Category {category.Name} visibility has changed to {category.get_Visible(doc.ActiveView)}."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetAdditionalInformation() => "Tracks visibility changes for categories.";
|
||||
|
||||
public ChangePriority GetChangePriority() => ChangePriority.Views;
|
||||
|
||||
public UpdaterId GetUpdaterId() => s_updaterId;
|
||||
|
||||
public string GetUpdaterName() => "VisibilityUpdater";
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
namespace Speckle.Connectors.Revit.Plugin;
|
||||
|
||||
public class CategoryVisibilityTracker
|
||||
{
|
||||
private readonly Document _doc;
|
||||
private readonly Dictionary<ElementId, bool> _visibilityStates;
|
||||
|
||||
public CategoryVisibilityTracker(Document doc)
|
||||
{
|
||||
_doc = doc;
|
||||
_visibilityStates = new Dictionary<ElementId, bool>();
|
||||
InitializeVisibilityStates();
|
||||
}
|
||||
|
||||
private void InitializeVisibilityStates()
|
||||
{
|
||||
foreach (Category category in _doc.Settings.Categories)
|
||||
{
|
||||
if (category.get_AllowsVisibilityControl(_doc.ActiveView))
|
||||
{
|
||||
_visibilityStates[category.Id] = category.get_Visible(_doc.ActiveView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasVisibilityChanged(Category category)
|
||||
{
|
||||
if (_visibilityStates.TryGetValue(category.Id, out bool previousState))
|
||||
{
|
||||
bool currentState = category.get_Visible(_doc.ActiveView);
|
||||
if (currentState != previousState)
|
||||
{
|
||||
_visibilityStates[category.Id] = currentState; // Update the state
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -16,6 +17,8 @@ internal sealed class RevitExternalApplication : IExternalApplication
|
||||
private ServiceProvider? _container;
|
||||
private IDisposable? _disposableLogger;
|
||||
|
||||
private UpdaterId? _updaterId;
|
||||
|
||||
// POC: move to somewhere central?
|
||||
public static readonly DockablePaneId DockablePanelId = new(new Guid("{f7b5da7c-366c-4b13-8455-b56f433f461e}"));
|
||||
|
||||
@@ -51,6 +54,9 @@ internal sealed class RevitExternalApplication : IExternalApplication
|
||||
// resolve root object
|
||||
_revitPlugin = _container.GetRequiredService<IRevitPlugin>();
|
||||
_revitPlugin.Initialise();
|
||||
|
||||
application.ControlledApplication.DocumentOpened += OnDocumentOpened;
|
||||
application.ControlledApplication.DocumentClosed += OnDocumentClosed;
|
||||
}
|
||||
catch (Exception e) when (!e.IsFatal())
|
||||
{
|
||||
@@ -84,4 +90,25 @@ internal sealed class RevitExternalApplication : IExternalApplication
|
||||
|
||||
return Result.Succeeded;
|
||||
}
|
||||
|
||||
private void OnDocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
|
||||
{
|
||||
var doc = e.Document;
|
||||
|
||||
// Register the updater
|
||||
var updater = new VisibilityUpdater(doc.Application.ActiveAddInId, doc);
|
||||
UpdaterRegistry.RegisterUpdater(updater);
|
||||
|
||||
_updaterId = updater.GetUpdaterId();
|
||||
|
||||
// Set triggers for the updater
|
||||
UpdaterRegistry.AddTrigger(
|
||||
updater.GetUpdaterId(),
|
||||
new ElementClassFilter(typeof(View)),
|
||||
Element.GetChangeTypeAny()
|
||||
);
|
||||
}
|
||||
|
||||
private void OnDocumentClosed(object sender, Autodesk.Revit.DB.Events.DocumentClosedEventArgs e) =>
|
||||
UpdaterRegistry.UnregisterUpdater(_updaterId);
|
||||
}
|
||||
|
||||
+2
@@ -44,6 +44,8 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\Settings\ToSpeckleSettingsManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\Settings\ReferencePointSetting.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\Settings\DetailLevelSetting.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Plugin\CategoryTracker.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Plugin\CategoryVisiblityTracker.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Plugin\IRevitPlugin.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Plugin\RevitCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Plugin\RevitExternalApplication.cs" />
|
||||
|
||||
Reference in New Issue
Block a user