using Autodesk.Revit.DB; using Autodesk.Revit.DB.Electrical; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Windows; using System.Windows.Input; namespace Szmedi.RvKits.MEPTools { public partial class CableLayoutViewModel : ObservableValidator { private Document doc; public CableLayoutViewModel(Document doc) { this.doc = doc; specifications = new FilteredElementCollector(doc).OfClass(typeof(ConduitType)).Cast().ToList(); } [ObservableProperty] private ConduitType selectedConduitType; private int count; [Range(1, 20, ErrorMessage = "输入值有误!")] public int Count { get => count; set => SetProperty(ref count, value, true); } [ObservableProperty] private List specifications; [ObservableProperty] private ConduitSize size; [ObservableProperty] private Dictionary sizes; //public void m(doc doc) //{ // var set = ConduitSizeSettings.GetConduitSizeSettings(doc); // set.GetSizeCount(); //} private RelayCommand closeWin; public ICommand CloseWin { get { closeWin ??= new RelayCommand(PerformCloseWin); return closeWin; } } private void PerformCloseWin(object obj) { if (obj is Window && Count > 0 && Size != null && SelectedConduitType != null) { Window window = (Window)obj; window.DialogResult = true; } } private RelayCommand selectionType; public ICommand SelectionType { get { selectionType ??= new RelayCommand(PerformSelectionType); return selectionType; } } private void PerformSelectionType() { IEnumerator> 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) { string key = (size.NominalDiameter * 304.8).ToString(); dictionary.Add(key, size); } } Sizes = dictionary; } } }