using System.ComponentModel.DataAnnotations; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Electrical; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace ShrlAlgoToolkit.RevitAddins.RvMEP; public partial class CableLayoutViewModel : ObservableValidator { private readonly Document doc; public CableLayoutViewModel(Document doc) { this.doc = doc; Specifications = new FilteredElementCollector(doc).OfClass(typeof(ConduitType)).Cast().ToList(); } [ObservableProperty] public partial ConduitType SelectedConduitType { get; set; } [Range(1, 20, ErrorMessage = "输入值有误!")] [ObservableProperty] [NotifyDataErrorInfo] public partial int Count { get; set; } //public int Count //{ // get => count; // set => SetProperty(ref count, value, true); //} [ObservableProperty] public partial List Specifications { get; set; } [ObservableProperty] public partial ConduitSize Size { get; set; } [ObservableProperty] public partial Dictionary Sizes { get; set; } [RelayCommand] private void CloseWin(object obj) { if (obj is System.Windows.Window window && Count > 0 && Size != null && SelectedConduitType != null) { window.DialogResult = true; } } [RelayCommand] private void SelectionType() { var enumerator = ConduitSizeSettings.GetConduitSizeSettings(doc).GetEnumerator(); var standardName = SelectedConduitType.get_Parameter(BuiltInParameter.CONDUIT_STANDARD_TYPE_PARAM).AsValueString(); ConduitSizes sizes = null; Dictionary dictionary = new(); while (enumerator.MoveNext()) { var current = enumerator.Current; if (current.Key == standardName) { sizes = current.Value; break; } } if (sizes != null) { foreach (var size in sizes) { var key = (size.NominalDiameter * 304.8).ToString(); dictionary.Add(key, size); } } Sizes = dictionary; } }