Skip to content

Commit fa5ccfd

Browse files
committed
refine selector: elements on the screen
1 parent b0a12e2 commit fa5ccfd

File tree

6 files changed

+46
-66
lines changed

6 files changed

+46
-66
lines changed

sources/RevitDBExplorer/Application.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void UIApplication_ViewActivated(object sender, Autodesk.Revit.UI.Events
110110
if (e.CurrentActiveView != null)
111111
{
112112
var uiViews = UIApplication.ActiveUIDocument.GetOpenUIViews();
113-
UIView = uiViews.FirstOrDefault(x => x.ViewId == e.CurrentActiveView.Id);
113+
UIView = uiViews.FirstOrDefault(x => x.ViewId == e.CurrentActiveView.Id);
114114
View = e.CurrentActiveView;
115115
}
116116
else
@@ -153,20 +153,25 @@ public static (string, XYZ, XYZ, bool) GetMouseStatus()
153153

154154
var upDirection = view.UpDirection;
155155
var forwardDirection = view.ViewDirection;
156+
var rightDirection = view.RightDirection;
156157

157158
if (view is View3D view3D)
158159
{
159160
if (view3D.IsPerspective)
160161
{
161-
return ("(?,,)", min, max, false);
162+
return ("(IsPerspective == true)", min, max, false);
162163
}
163164

164165
var orientation = view3D.GetOrientation();
165166
upDirection = orientation.UpDirection;
166167
forwardDirection = orientation.ForwardDirection;
167-
}
168-
169-
var rightDirection = forwardDirection.CrossProduct(upDirection).Normalize();
168+
}
169+
170+
var rightDirection2 = forwardDirection.CrossProduct(upDirection).Normalize();
171+
if (rightDirection2.IsParallelTo(rightDirection) == false)
172+
{
173+
174+
}
170175

171176
var diagVector = corners[0] - corners[1];
172177
double height = Math.Abs(diagVector.DotProduct(view.UpDirection));
@@ -187,7 +192,7 @@ public static (string, XYZ, XYZ, bool) GetMouseStatus()
187192
return ($"({r.X:f3}, {r.Y:f3}, -,--)", min, max, true);
188193
}
189194

190-
return ("(-,--,-,--,-,--)", XYZ.Zero, XYZ.Zero, true);
195+
return ("(not parallel)", XYZ.Zero, XYZ.Zero, true);
191196
}
192197
catch
193198
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using Autodesk.Revit.DB;
3+
using RevitDBExplorer.Domain.DataModel.Members;
4+
using RevitDBExplorer.Domain.DataModel.Members.Base;
5+
6+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
7+
8+
namespace RevitDBExplorer.Domain.DataModel.MembersTemplates
9+
{
10+
internal class ModelPath_Templates : IHaveMemberTemplates
11+
{
12+
public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
13+
[
14+
#if R2022_MIN
15+
16+
#endif
17+
//MemberTemplate<ModelPath>.Create((doc, target) => ModelPathUtils.CloudRegionEMEA),
18+
//MemberTemplate<ModelPath>.Create((doc, target) => ModelPathUtils.CloudRegionUS),
19+
MemberTemplate<ModelPath>.Create((doc, target) => ModelPathUtils.ConvertModelPathToUserVisiblePath(target)),
20+
];
21+
}
22+
}
Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using Autodesk.Revit.DB;
53
using Autodesk.Revit.UI;
64
using RevitDBExplorer.Domain.DataModel;
75
using RevitDBExplorer.Domain.Selectors.Base;
@@ -17,50 +15,12 @@ internal class SnoopElementsOnScreen : ISelector
1715
public IEnumerable<SnoopableObject> Snoop(UIApplication app)
1816
{
1917
var document = app?.ActiveUIDocument?.Document;
18+
var view = document?.ActiveView;
19+
if (view == null ) return null;
2020

21-
if (document == null) return null;
22-
23-
if (document.ActiveView is ViewPlan viewPlan)
24-
{
25-
//var currentElevation = viewPlan.GenLevel.Elevation;
26-
//var bottomElevation = -1000.0;
27-
28-
//var viewRange = viewPlan.GetViewRange();
29-
//var depthPlaneLevelId = viewRange.GetLevelId(PlanViewPlane.ViewDepthPlane);
30-
//if (depthPlaneLevelId != ElementId.InvalidElementId)
31-
//{
32-
// var depthOffset = viewRange.GetOffset(PlanViewPlane.ViewDepthPlane);
33-
// var depthLevel = document.GetElement(depthPlaneLevelId) as Level;
34-
// bottomElevation = depthLevel.Elevation + depthOffset;
35-
//}
36-
37-
//var deltaBottom = currentElevation - bottomElevation;
38-
}
39-
40-
var view = app.ActiveUIDocument.ActiveGraphicalView;
41-
if (view == null) return null;
42-
43-
if (view.ViewDirection.IsParallelTo(XYZ.BasisX) == false && view.ViewDirection.IsParallelTo(XYZ.BasisY) == false && view.ViewDirection.IsParallelTo(XYZ.BasisZ) == false)
44-
return null;
45-
if (view.RightDirection.IsParallelTo(XYZ.BasisX) == false && view.RightDirection.IsParallelTo(XYZ.BasisY) == false && view.RightDirection.IsParallelTo(XYZ.BasisZ) == false)
46-
return null;
47-
48-
var uiViews = app.ActiveUIDocument.GetOpenUIViews();
49-
var uiView = uiViews.FirstOrDefault(x => x.ViewId == document.ActiveView.Id);
50-
var zoomCorners = uiView.GetZoomCorners();
51-
var min = zoomCorners[0];
52-
var max = zoomCorners[1];
21+
var elements = app.ActiveUIDocument.GetElementsOnTheScreen().Select(x => new SnoopableObject(document, x)).ToArray();
5322

54-
var margin1 = document.ActiveView.ViewDirection * 54321;
55-
var margin2 = margin1.Negate();
56-
57-
min = min + margin1.Min(margin2);
58-
max = max + margin1.Max(margin2);
59-
60-
var outline = new Outline(min, max);
61-
var collector = new FilteredElementCollector(document, document.ActiveView.Id).WherePasses(new BoundingBoxIntersectsFilter(outline));
62-
63-
return collector.ToElements().Select(x => new SnoopableObject(document, x));
64-
}
23+
return elements;
24+
}
6525
}
66-
}
26+
}

sources/RevitDBExplorer/Extensions/Autodesk.Revit.DB/XYZExtensions.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ public static bool IsCodirectionalTo(this XYZ first, XYZ second)
2121
var dotProduct = first.Normalize().DotProduct(second.Normalize());
2222

2323
return Math.Abs(dotProduct - 1.0) < 1e-6;
24-
}
25-
26-
public static XYZ Min(this XYZ first, XYZ second)
27-
{
28-
return new XYZ(Math.Min(first.X, second.X), Math.Min(first.Y, second.Y), Math.Min(first.Z, second.Z));
29-
}
30-
31-
public static XYZ Max(this XYZ first, XYZ second)
32-
{
33-
return new XYZ(Math.Max(first.X, second.X), Math.Max(first.Y, second.Y), Math.Max(first.Z, second.Z));
34-
}
24+
}
3525
}
36-
}
26+
}

sources/RevitDBExplorer/RevitDBExplorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<PackageReference Include="CircularBuffer" Version="1.4.0" />
8989
<PackageReference Include="LoxSmoke.DocXml" Version="3.7.1" />
9090
<PackageReference Include="NSourceGenerators.CodeToString" Version="0.4.0" />
91-
<PackageReference Include="RevitExplorer.Augmentations" Version="1.4.1.$(RevitYear)" />
91+
<PackageReference Include="RevitExplorer.Augmentations" Version="1.4.2.$(RevitYear)" />
9292
<PackageReference Include="RevitExplorer.Scripting" Version="1.4.2.$(RevitYear)" />
9393
<PackageReference Include="RevitExplorer.Visualizations" Version="1.4.0.$(RevitYear)" />
9494
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />

sources/RevitDBExplorer/UIComponents/Trees/Explorer/ExplorerTreeViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ private void PopulateElementIdTreeItemMap()
210210
}
211211
private void SynchronizeSelectionWithRevit()
212212
{
213+
if (sourceOfObjects == null)
214+
return;
215+
213216
var uiDocument = new UIDocument(sourceOfObjects.RevitDocument);
214217
selectedTreeItemsInRevit.ForEach(x => x.IsSelectedInRevit = false);
215218
selectedTreeItemsInRevit.Clear();

0 commit comments

Comments
 (0)