Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ec45d3cd5 | |||
| ac1345bbaf |
@@ -3,8 +3,6 @@ using Autodesk.Revit.DB;
|
||||
using Speckle.Connectors.DUI.Models.Card.SendFilter;
|
||||
using Speckle.Connectors.RevitShared;
|
||||
using Speckle.Connectors.RevitShared.Operations.Send.Filters;
|
||||
using Speckle.Converters.RevitShared.Helpers;
|
||||
using Speckle.Sdk.Common;
|
||||
|
||||
namespace Speckle.Connectors.Revit.HostApp;
|
||||
|
||||
@@ -16,14 +14,9 @@ namespace Speckle.Connectors.Revit.HostApp;
|
||||
/// </summary>
|
||||
public class LinkedModelHandler
|
||||
{
|
||||
private readonly RevitContext _revitContext;
|
||||
// Dictionary to track linked model display names
|
||||
public Dictionary<string, string> LinkedModelDisplayNames { get; } = new();
|
||||
|
||||
public LinkedModelHandler(RevitContext revitContext)
|
||||
{
|
||||
_revitContext = revitContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets elements from a linked document based on the provided send filter.
|
||||
/// This method handles the specifics of element collection but doesn't make decisions
|
||||
@@ -45,36 +38,6 @@ public class LinkedModelHandler
|
||||
}
|
||||
return new List<Element>();
|
||||
}
|
||||
|
||||
// send mode → Views (taken from the legacy code)
|
||||
if (sendFilter is RevitViewsFilter viewFilter && viewFilter.GetView() != null)
|
||||
{
|
||||
RevitLinkInstance linkInstance = FindLinkInstanceForDocument(
|
||||
linkedDocument.PathName,
|
||||
_revitContext.UIApplication.NotNull().ActiveUIDocument.Document
|
||||
);
|
||||
|
||||
#if REVIT2024_OR_GREATER
|
||||
// revit 2024 and 2025 we can use the three-parameter constructor to get only visible elements
|
||||
using var viewCollector = new FilteredElementCollector(
|
||||
_revitContext.UIApplication.ActiveUIDocument.Document,
|
||||
viewFilter.GetView().NotNull().Id,
|
||||
linkInstance.Id
|
||||
);
|
||||
return viewCollector.WhereElementIsNotElementType().ToElements().ToList();
|
||||
#else
|
||||
// 🚨 LIMITATION: in Revit 2023 and below, we can only check if the entire linked model is visible,
|
||||
// not individual elements within it. If the linked model is visible, all its elements will be included.
|
||||
// constructor overload pertaining to searching and filtering visible elements from a revit link only added 2024.
|
||||
if (linkInstance.IsHidden(viewFilter.GetView().NotNull()))
|
||||
{
|
||||
return new List<Element>(); // if the linked model is hidden, return no elements
|
||||
}
|
||||
// 💩 fallback to getting all elements if the linked model is visible
|
||||
return GetAllElementsForLinkedModelSelection(linkedDocument);
|
||||
#endif
|
||||
}
|
||||
|
||||
// send mode → Selection
|
||||
return GetAllElementsForLinkedModelSelection(linkedDocument);
|
||||
}
|
||||
@@ -165,14 +128,4 @@ public class LinkedModelHandler
|
||||
using var collector = new FilteredElementCollector(linkedDoc);
|
||||
return collector.WhereElementIsNotElementType().WhereElementIsViewIndependent().ToList();
|
||||
}
|
||||
|
||||
private RevitLinkInstance FindLinkInstanceForDocument(string linkedDocumentPath, Document mainDocument)
|
||||
{
|
||||
using var collector = new FilteredElementCollector(mainDocument);
|
||||
return collector
|
||||
.OfClass(typeof(RevitLinkInstance))
|
||||
.Cast<RevitLinkInstance>()
|
||||
.FirstOrDefault(link => link.GetLinkDocument()?.PathName == linkedDocumentPath)
|
||||
.NotNull();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-2
@@ -5,6 +5,7 @@ using Speckle.Connectors.Common.Caching;
|
||||
using Speckle.Connectors.Common.Conversion;
|
||||
using Speckle.Connectors.Common.Extensions;
|
||||
using Speckle.Connectors.Common.Operations;
|
||||
using Speckle.Connectors.Common.Threading;
|
||||
using Speckle.Connectors.DUI.Exceptions;
|
||||
using Speckle.Connectors.Revit.HostApp;
|
||||
using Speckle.Converters.Common;
|
||||
@@ -22,6 +23,7 @@ public class RevitRootObjectBuilder(
|
||||
IConverterSettingsStore<RevitConversionSettings> converterSettings,
|
||||
ISendConversionCache sendConversionCache,
|
||||
ElementUnpacker elementUnpacker,
|
||||
IThreadContext threadContext,
|
||||
SendCollectionManager sendCollectionManager,
|
||||
ILogger<RevitRootObjectBuilder> logger,
|
||||
RevitToSpeckleCacheSingleton revitToSpeckleCacheSingleton,
|
||||
@@ -33,6 +35,16 @@ public class RevitRootObjectBuilder(
|
||||
SendInfo sendInfo,
|
||||
IProgress<CardProgress> onOperationProgressed,
|
||||
CancellationToken ct = default
|
||||
) =>
|
||||
threadContext.RunOnMainAsync(
|
||||
() => Task.FromResult(BuildSync(documentElementContexts, sendInfo, onOperationProgressed, ct))
|
||||
);
|
||||
|
||||
private RootObjectBuilderResult BuildSync(
|
||||
IReadOnlyList<DocumentToConvert> documentElementContexts,
|
||||
SendInfo sendInfo,
|
||||
IProgress<CardProgress> onOperationProgressed,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var doc = converterSettings.Current.Document;
|
||||
@@ -143,7 +155,7 @@ public class RevitRootObjectBuilder(
|
||||
var atomicObjects = atomicObjectByDocumentAndTransform.Elements;
|
||||
foreach (Element revitElement in atomicObjects)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
string applicationId = revitElement.UniqueId;
|
||||
string sourceType = revitElement.GetType().Name;
|
||||
try
|
||||
@@ -229,6 +241,6 @@ public class RevitRootObjectBuilder(
|
||||
// NOTE: these are currently not used anywhere, we'll skip them until someone calls for it back
|
||||
// rootObject[ProxyKeys.PARAMETER_DEFINITIONS] = _parameterDefinitionHandler.Definitions;
|
||||
|
||||
return Task.FromResult(new RootObjectBuilderResult(rootObject, results));
|
||||
return new RootObjectBuilderResult(rootObject, results);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public abstract class DocumentModelStore(IJsonSerializer serializer)
|
||||
}
|
||||
}
|
||||
|
||||
protected string Serialize() => serializer.Serialize(Models.ToList());
|
||||
protected string Serialize() => serializer.Serialize(Models);
|
||||
|
||||
// POC: this seemms more like a IModelsDeserializer?, seems disconnected from this class
|
||||
protected List<ModelCard> Deserialize(string models) => serializer.Deserialize<List<ModelCard>>(models).NotNull();
|
||||
|
||||
Reference in New Issue
Block a user