多项功能优化

This commit is contained in:
GG Z
2024-12-22 10:26:12 +08:00
parent 77655c9ef5
commit 83b846f15f
66 changed files with 5424 additions and 2927 deletions

View File

@@ -15,14 +15,14 @@ namespace Sai.RvKits.RvView;
public partial class SectionBoxControllerViewModel : ObservableObject
{
public SectionBoxControllerViewModel(UIDocument uidoc)
public SectionBoxControllerViewModel(UIApplication uiapp)
{
uidoc.Application.ViewActivated -= Application_ViewActivated;
uidoc.Application.ViewActivated += Application_ViewActivated;
uiapp.ViewActivated -= Application_ViewActivated;
uiapp.ViewActivated += Application_ViewActivated;
if (uidoc.ActiveView is View3D view3d)
if (uiapp.ActiveUIDocument.ActiveView is View3D view3d)
{
using var trans = new Transaction(uidoc.Document, "激活剖面框");
using var trans = new Transaction(uiapp.ActiveUIDocument.Document, "激活剖面框");
trans.Start();
if (!view3d.IsSectionBoxActive)
{
@@ -37,7 +37,7 @@ public partial class SectionBoxControllerViewModel : ObservableObject
CanModify = false;
}
setSectionBoxHandler = new ActionEventHandler();
this.uidoc = uidoc;
this.uiapp = uiapp;
}
private void Application_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
@@ -58,13 +58,13 @@ public partial class SectionBoxControllerViewModel : ObservableObject
public ObservableCollection<SectionBox> BoundingBoxes { get; set; } = [];
private readonly ActionEventHandler setSectionBoxHandler;
private readonly UIDocument uidoc;
private readonly UIApplication uiapp;
private int index = 1;
[RelayCommand(CanExecute = nameof(CanModify))]
private void RecordSectionBox()
{
if (uidoc.Document.ActiveView is View3D { IsSectionBoxActive: true } view3D)
if (uiapp.ActiveUIDocument.Document.ActiveView is View3D { IsSectionBoxActive: true } view3D)
{
BoundingBoxes.Insert(0, new SectionBox($"剖面框 {index}", view3D.GetSectionBox()));
index++;
@@ -78,19 +78,19 @@ public partial class SectionBoxControllerViewModel : ObservableObject
[RelayCommand]
private void ResetSectionBox()
{
setSectionBoxHandler.Raise(_ =>
setSectionBoxHandler.Raise(uiapp =>
{
var doc = uidoc.Document;
var uidoc = uiapp.ActiveUIDocument;
switch (SectionBoxType)
{
case SectionBoxType.Element:
ResetSectionBoxByElement();
ResetSectionBoxByElement(uidoc);
break;
case SectionBoxType.Rectangle:
ResetSectionBoxByRectangle();
ResetSectionBoxByRectangle(uidoc);
break;
case SectionBoxType.ViewSection:
ResetSectionBoxByViewSection();
ResetSectionBoxByViewSection(uidoc);
break;
default:
break;
@@ -101,7 +101,7 @@ public partial class SectionBoxControllerViewModel : ObservableObject
/// <summary>
/// 重设元素剖面框
/// </summary>
private void ResetSectionBoxByElement()
private void ResetSectionBoxByElement(UIDocument uidoc)
{
var doc = uidoc.Document;
doc.Invoke(
@@ -163,10 +163,9 @@ public partial class SectionBoxControllerViewModel : ObservableObject
/// <summary>
/// 重设框选剖面框
/// </summary>
private void ResetSectionBoxByRectangle()
private void ResetSectionBoxByRectangle(UIDocument uidoc)
{
var doc = uidoc.Document;
doc.Invoke(
ts =>
{
@@ -207,7 +206,7 @@ public partial class SectionBoxControllerViewModel : ObservableObject
/// <summary>
/// 重设剖面视图范围的剖面框
/// </summary>
private void ResetSectionBoxByViewSection()
private void ResetSectionBoxByViewSection(UIDocument uidoc)
{
var reference = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new FuncFilter(elem => elem.Category?.GetHashCode() == -2000278), "请选择剖面视图");
var doc = uidoc.Document;
@@ -266,8 +265,9 @@ public partial class SectionBoxControllerViewModel : ObservableObject
{
if (obj is BoundingBoxXYZ boundingBoxXyz)
{
setSectionBoxHandler.Raise(_ =>
setSectionBoxHandler.Raise(uiapp =>
{
var uidoc = uiapp.ActiveUIDocument;
if (uidoc.ActiveView is View3D view3d)
{
uidoc.Document.Invoke(_ =>