Files
ShrlAlgoToolkit/ShrlAlgoToolkit.RevitAddins/RvMEP/CableLayoutViewModel.cs

78 lines
2.1 KiB
C#
Raw Normal View History

2025-04-24 20:56:44 +08:00
using System.ComponentModel.DataAnnotations;
using System.Windows;
2024-09-22 11:05:41 +08:00
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
2025-04-24 20:56:44 +08:00
namespace ShrlAlgoToolkit.RevitAddins.RvMEP;
2024-09-22 11:05:41 +08:00
public partial class CableLayoutViewModel : ObservableValidator
{
private readonly Document doc;
public CableLayoutViewModel(Document doc)
{
this.doc = doc;
specifications = new FilteredElementCollector(doc).OfClass(typeof(ConduitType)).Cast<ConduitType>().ToList();
}
[ObservableProperty]
private ConduitType selectedConduitType;
[Range(1, 20, ErrorMessage = "输入值有误!")]
[ObservableProperty]
[NotifyDataErrorInfo]
private int count;
//public int Count
//{
// get => count;
// set => SetProperty(ref count, value, true);
//}
[ObservableProperty]
private List<ConduitType> specifications;
[ObservableProperty]
private ConduitSize size;
[ObservableProperty]
private Dictionary<string, ConduitSize> sizes;
[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<string, ConduitSize> 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;
}
}