Skip to content

Commit

Permalink
Pass new UIDocument instance in after view init callback
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed May 29, 2024
1 parent 2988e57 commit 8f3fa55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/IPA.Bcfier.Revit/Models/ViewContinuationInstructions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace IPA.Bcfier.Revit.Models
{
public class ViewContinuationInstructions
{
public Action? ViewContinuation { get; set; }
public Action<UIDocument>? ViewContinuation { get; set; }

public ElementId? ViewId { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/IPA.Bcfier.Revit/RevitTaskQueueHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void HandlAfterViewCreationCallbackQueueItems(UIDocument uiDocument)
var item = AfterViewCreationCallbackQueue.Dequeue();
if (item?.ViewId == uiDocument.ActiveView.Id)
{
item.ViewContinuation?.Invoke();
item.ViewContinuation?.Invoke(uiDocument);
Task.Run(async () =>
{
if (item != null && item.Callback != null)
Expand Down
24 changes: 12 additions & 12 deletions src/IPA.Bcfier.Revit/Services/RevitViewpointDisplayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public RevitViewpointDisplayService(UIDocument uiDocument)
return null;
}

Action viewContinuation = () =>
Action<UIDocument> viewContinuation = (uiDocument) =>
{
if (bcfViewpoint.ViewpointComponents == null)
{
Expand All @@ -156,25 +156,25 @@ public RevitViewpointDisplayService(UIDocument uiDocument)
_uiDocument.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr);
}

var baseViewTemplate = new FilteredElementCollector(doc)
var baseViewTemplate = new FilteredElementCollector(uiDocument.Document)
.OfClass(typeof(View))
.Cast<View>()
.Where(view => view.IsTemplate && view.Name.Contains("3D") && view.Name.Contains("IPA BCF"))
.FirstOrDefault();
if (baseViewTemplate != null)
{
doc.ActiveView.ApplyViewTemplateParameters(baseViewTemplate);
uiDocument.Document.ActiveView.ApplyViewTemplateParameters(baseViewTemplate);
}

var elementsToSelect = new List<ElementId>();
var elementsToHide = new List<ElementId>();
var elementsToShow = new List<ElementId>();

var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id)
var visibleElems = new FilteredElementCollector(uiDocument.Document, uiDocument.Document.ActiveView.Id)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElementIds()
.Where(e => doc.GetElement(e).CanBeHidden(doc.ActiveView)); //might affect performance, but it's necessary
.Where(e => uiDocument.Document.GetElement(e).CanBeHidden(uiDocument.Document.ActiveView)); //might affect performance, but it's necessary

bool canSetVisibility = (bcfViewpoint.ViewpointComponents.Visibility != null &&
bcfViewpoint.ViewpointComponents.Visibility.DefaultVisibility &&
Expand Down Expand Up @@ -213,29 +213,29 @@ public RevitViewpointDisplayService(UIDocument uiDocument)
}
}

using (var trans = new Transaction(_uiDocument.Document))
using (var trans = new Transaction(uiDocument.Document))
{
if (trans.Start("Apply BCF visibility and selection and section box") == TransactionStatus.Started)
{
if (elementsToHide.Any())
doc.ActiveView.HideElementsTemporary(elementsToHide);
uiDocument.Document.ActiveView.HideElementsTemporary(elementsToHide);
//there are no items to hide, therefore hide everything and just show the visible ones
else if (elementsToShow.Any())
doc.ActiveView.IsolateElementsTemporary(elementsToShow);
uiDocument.Document.ActiveView.IsolateElementsTemporary(elementsToShow);

if (elementsToSelect.Any())
_uiDocument.Selection.SetElementIds(elementsToSelect);
uiDocument.Selection.SetElementIds(elementsToSelect);

if (_uiDocument.ActiveView is View3D view3d)
if (uiDocument.ActiveView is View3D view3d)
{
ApplyClippingPlanes(_uiDocument, view3d, bcfViewpoint);
ApplyClippingPlanes(uiDocument, view3d, bcfViewpoint);
}
}

trans.Commit();
}

_uiDocument.RefreshActiveView();
uiDocument.RefreshActiveView();
};

return new ViewContinuationInstructions
Expand Down

0 comments on commit 8f3fa55

Please sign in to comment.