整理代码
This commit is contained in:
83
ShrlAlgoToolkit.RevitAddins/RvMEP/CableLayoutViewModel.cs
Normal file
83
ShrlAlgoToolkit.RevitAddins/RvMEP/CableLayoutViewModel.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Electrical;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ShrlAlgo.RvKits.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<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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user