调整代码
This commit is contained in:
78
ShrlAlgoToolkit.RevitAddins/Mep/CableLayoutViewModel.cs
Normal file
78
ShrlAlgoToolkit.RevitAddins/Mep/CableLayoutViewModel.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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<ConduitType>().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<ConduitType> Specifications { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial ConduitSize Size { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial Dictionary<string, ConduitSize> 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<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