using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace Sai.Common.Shared.WBSCoder { public partial class ComponentCodeAddedCheckerViewModel : ObservableObject { public ComponentCodeAddedCheckerViewModel(CheckCodeViewModel viewModel) { uidoc = viewModel.Uidoc; pjFileName = viewModel.ProjectPath; allElements = viewModel.AllElements; LastTaskItems = viewModel.LastTaskItems; } private readonly IList allElements; private readonly string pjFileName; private readonly UIDocument uidoc; public ObservableCollection LastTaskItems; private RelayCommand showElement; public ObservableCollection ElementsWithErrorCode { get; set; } = new(); private bool CanCheckComponent() { //检查构件是否存在没有编码的情况 return pjFileName != null; } /// /// 检查构件是否都编码 /// /// [RelayCommand(CanExecute = nameof(CanCheckComponent))] private void CheckComponents(object obj) { ElementsWithErrorCode.Clear(); foreach (var ele in allElements) { bool hasCoded = false; var temp = ele.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)?.AsString(); if (temp == null) { continue; } string code = WbsCoderUtils.FormatWbsCode(temp); foreach (var task in LastTaskItems) { if (task.WBSCode == code) { hasCoded = true; break; } } if (!hasCoded) { ElementsWithErrorCode.Add(ele); } //var select = from task in LastTaskItems // where task.WBSCode == code // select task; //if (!param.HasValue || select.Count() == 0) //{ // ElementsWithErrorCode.Add(ele); //} } } /// /// 定位元素 /// /// [RelayCommand] private void LocationElement(object obj) { try { Element element = (Element)obj; List ids = new List(); ids.Add(element.Id); uidoc.Selection.SetElementIds(ids); uidoc.ShowElements(element); } catch (Exception ex) { TaskDialog.Show("定位失败", $"{ex.Message}"); } } } }