Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ public void HighlightModel(string modelCardId)
{
SenderModelCard model = (SenderModelCard)_store.GetModelById(modelCardId);

var elementIds = model.SendFilter.NotNull().GetObjectIds().Select(ElementIdHelper.Parse).ToList();
var activeUIDoc =
_revitContext.UIApplication?.ActiveUIDocument
?? throw new SpeckleException("Unable to retrieve active UI document");

var elementIds = model
.SendFilter.NotNull()
.GetObjectIds()
.Select(uid => ElementIdHelper.GetElementIdByUniqueId(activeUIDoc.Document, uid))
.ToList();
if (elementIds.Count == 0)
{
Commands.SetModelError(modelCardId, new InvalidOperationException("No objects found to highlight."));
Expand All @@ -87,8 +95,20 @@ public void HighlightModel(string modelCardId)
HighlightObjectsOnView(elementIds);
}

public void HighlightObjects(List<string> objectIds) =>
HighlightObjectsOnView(objectIds.Select(ElementIdHelper.Parse).ToList());
/// <summary>
/// Highlights the objects from the given ids.
/// </summary>
/// <param name="objectIds"> UniqueId's of the DB.Elements.</param>
public void HighlightObjects(List<string> objectIds)
{
var activeUIDoc =
_revitContext.UIApplication?.ActiveUIDocument
?? throw new SpeckleException("Unable to retrieve active UI document");

HighlightObjectsOnView(
objectIds.Select(uid => ElementIdHelper.GetElementIdByUniqueId(activeUIDoc.Document, uid)).ToList()
);
}

private void HighlightObjectsOnView(List<ElementId> objectIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ public async Task Send(string modelCardId)
}
);

var activeUIDoc =
RevitContext.UIApplication?.ActiveUIDocument
?? throw new SpeckleException("Unable to retrieve active UI document");

List<ElementId> revitObjects = modelCard
.SendFilter.NotNull()
.GetObjectIds()
.Select(ElementIdHelper.Parse)
.Select(uid => ElementIdHelper.GetElementIdByUniqueId(activeUIDoc.Document, uid))
.ToList();

if (revitObjects.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public SelectionInfo GetSelection()
return new SelectionInfo(Array.Empty<string>(), "No objects selected.");
}

var activeUIDoc = RevitContext.UIApplication.ActiveUIDocument.NotNull();

// POC: this was also being called on shutdown
// probably the bridge needs to be able to know if the plugin has been terminated
// also on termination the OnSelectionChanged event needs unwinding
var selectionIds = (RevitContext.UIApplication?.ActiveUIDocument?.Selection.GetElementIds())
.NotNull()
.Select(id => id.ToString())
var selectionIds = activeUIDoc
.Selection.GetElementIds()
.Select(eid => activeUIDoc.Document.GetElement(eid).UniqueId.ToString())
.ToList();
return new SelectionInfo(selectionIds, $"{selectionIds.Count} objects selected.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ namespace Speckle.Connectors.RevitShared;

public static class ElementIdHelper
{
public static ElementId Parse(string idStr)
public static ElementId GetElementIdByUniqueId(Document doc, string uniqueId)
{
if (!int.TryParse(idStr, out var result))
Element element = doc.GetElement(uniqueId);
if (element == null)
{
throw new SpeckleConversionException($"Cannot parse ElementId: {idStr}");
throw new SpeckleConversionException($"Cannot find element with UniqueId: {uniqueId}");
}

return new ElementId(result);
return element.Id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private HostObjectBuilderResult BakeObjects(IEnumerable<TraversalContext> object
using (var _ = SpeckleActivityFactory.Start("BakeObjects"))
{
var conversionResults = new List<ReceiveConversionResult>();

// NOTE!!!! Add 'UniqueId' of the elements once we have receiving in place, otherwise highlight logic will fail.
var bakedObjectIds = new List<string>();

foreach (TraversalContext tc in objectsGraph)
Expand Down
Loading