using Autodesk.Revit.DB; using Autodesk.Revit.UI; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Nice3point.Revit.Toolkit.External.Handlers; namespace ShrlAlgo.RvKits.Windows; public partial class MessageViewModel : ObservableObject { public MessageViewModel(UIDocument uidoc, List 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 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 { model.Element.Id }; //UiDocument.ActiveView.IsolateElementTemporary(model.ElementToMove.ViewId); showElementsSectionBox.Raise( _ => { if (uidoc.ActiveView is not View3D view3d) { view3d = doc.OfClass().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); } } }