86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
|
|||
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace Sai.RvKits.Windows;
|
|||
|
|
|
|||
|
|
public partial class MessageViewModel : ObservableObject
|
|||
|
|
{
|
|||
|
|
public MessageViewModel(UIDocument uidoc, List<MessageModel> errorModels, string winTitle = "错误处理")
|
|||
|
|
{
|
|||
|
|
this.uidoc = uidoc;
|
|||
|
|
showElementsSectionBox = new ActionEventHandler();
|
|||
|
|
ErrorModels.AddRange(errorModels);
|
|||
|
|
WinTitle = winTitle;
|
|||
|
|
count = errorModels.Count();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private string footer;
|
|||
|
|
|
|||
|
|
private readonly UIDocument uidoc;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private List<MessageModel> errorModels = [];
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private string winTitle;
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private int count;
|
|||
|
|
private readonly ActionEventHandler showElementsSectionBox;
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void ShowElement(object obj)
|
|||
|
|
{
|
|||
|
|
if (obj is not MessageModel model)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var doc = uidoc.Document;
|
|||
|
|
//if (UiDocument.ActiveView.IsTemporaryHideIsolateActive())
|
|||
|
|
//{
|
|||
|
|
// UiDocument.ActiveView.temporary
|
|||
|
|
//}
|
|||
|
|
if (model.Element.IsValidObject)
|
|||
|
|
{
|
|||
|
|
if (model.Element.IsHidden(uidoc.ActiveView))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var ids = new List<ElementId> { model.Element.Id };
|
|||
|
|
//UiDocument.ActiveView.IsolateElementTemporary(model.Element.ViewId);
|
|||
|
|
showElementsSectionBox.Raise(
|
|||
|
|
_ =>
|
|||
|
|
{
|
|||
|
|
if (uidoc.ActiveView is not View3D view3d)
|
|||
|
|
{
|
|||
|
|
view3d = doc.OfClass<View3D>().FirstElement() as View3D;
|
|||
|
|
}
|
|||
|
|
if (!model.Element.ViewSpecific)
|
|||
|
|
{
|
|||
|
|
uidoc.ActiveView = view3d;
|
|||
|
|
}
|
|||
|
|
doc.Invoke(
|
|||
|
|
_ =>
|
|||
|
|
{
|
|||
|
|
if (uidoc.ActiveView is View3D)
|
|||
|
|
{
|
|||
|
|
view3d.SectionBoxElements(ids);
|
|||
|
|
}
|
|||
|
|
view3d.ZoomElements(uidoc, ids);
|
|||
|
|
uidoc.Selection.SetElementIds(ids);
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ErrorModels.Remove(model);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|