2024-10-27 00:19:48 +08:00
|
|
|
|
using Autodesk.Revit.DB;
|
|
|
|
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
|
|
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|
|
|
|
|
|
2026-02-22 20:03:42 +08:00
|
|
|
|
using ShrlAlgoToolkit.RevitAddins.RvMEP;
|
|
|
|
|
|
using ShrlAlgoToolkit;
|
|
|
|
|
|
using ShrlAlgoToolkit.RevitAddins;
|
2025-02-10 20:53:40 +08:00
|
|
|
|
|
2026-02-22 20:03:42 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Mep
|
2024-10-27 00:19:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
public partial class AddInsulationViewModel : ObservableObject
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ActionEventHandler addInsulationHandler = new();
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2026-02-22 20:03:42 +08:00
|
|
|
|
[NotifyCanExecuteChangedFor(nameof(Mep.AddInsulationViewModel.AddInsulationCommand))]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool AddToDuct { get; set; }
|
|
|
|
|
|
|
2024-10-27 00:19:48 +08:00
|
|
|
|
[ObservableProperty]
|
2026-02-22 20:03:42 +08:00
|
|
|
|
[NotifyCanExecuteChangedFor(nameof(Mep.AddInsulationViewModel.AddInsulationCommand))]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial bool AddToPipe { get; set; }
|
|
|
|
|
|
|
2024-10-27 00:19:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 定义的风管保温层
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial InsulationItem DuctInsulationItem { get; set; }
|
|
|
|
|
|
|
2024-10-27 00:19:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 定义的管道保温层
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2025-10-04 08:52:23 +08:00
|
|
|
|
public partial List<InsulationItem> PipeInsulationItems { get; set; }
|
|
|
|
|
|
|
2024-10-27 00:19:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 选中的风管系统类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2026-02-22 20:03:42 +08:00
|
|
|
|
[NotifyCanExecuteChangedFor(nameof(Mep.AddInsulationViewModel.AddInsulationCommand))]
|
2024-10-27 00:19:48 +08:00
|
|
|
|
|
|
|
|
|
|
private MechanicalSystemType selectedDuctSystem;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 选中的管道系统类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
2026-02-22 20:03:42 +08:00
|
|
|
|
[NotifyCanExecuteChangedFor(nameof(Mep.AddInsulationViewModel.AddInsulationCommand))]
|
2024-10-27 00:19:48 +08:00
|
|
|
|
private PipingSystemType selectedPipingSystemType;
|
|
|
|
|
|
|
|
|
|
|
|
public AddInsulationViewModel(Document doc)
|
|
|
|
|
|
{
|
|
|
|
|
|
PipingSystemTypes = doc.OfClass<PipingSystemType>().Cast<PipingSystemType>().ToList();
|
|
|
|
|
|
DuctSystemTypes = doc.OfClass<MechanicalSystemType>().Cast<MechanicalSystemType>().ToList();
|
|
|
|
|
|
DuctInsulationTypes = doc.OfClass<DuctInsulationType>().Cast<DuctInsulationType>().ToList();
|
|
|
|
|
|
PipeInsulationTypes = doc.OfClass<PipeInsulationType>().Cast<PipeInsulationType>().ToList();
|
|
|
|
|
|
PipeInsulationItems = [
|
|
|
|
|
|
new InsulationItem(){MinDiameter=15,MaxDiameter=25, Thickness=25,PipeInsulationType=PipeInsulationTypes.FirstOrDefault()},
|
|
|
|
|
|
new InsulationItem(){MinDiameter=32,MaxDiameter=80, Thickness=30,PipeInsulationType=PipeInsulationTypes.FirstOrDefault()},
|
|
|
|
|
|
new InsulationItem(){MinDiameter=100,MaxDiameter=1000, Thickness=35,PipeInsulationType=PipeInsulationTypes.FirstOrDefault()},
|
|
|
|
|
|
];
|
|
|
|
|
|
DuctInsulationItem = new() { Thickness = 50, DuctInsulationType = DuctInsulationTypes.FirstOrDefault() };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand(CanExecute = nameof(CanAdd))]
|
|
|
|
|
|
private void AddInsulation()
|
|
|
|
|
|
{
|
|
|
|
|
|
addInsulationHandler.Raise(
|
|
|
|
|
|
uiapp =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|
|
|
|
|
var doc = uidoc.Document;
|
|
|
|
|
|
doc.Invoke(
|
2025-10-04 08:52:23 +08:00
|
|
|
|
_ =>
|
2024-10-27 00:19:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (AddToDuct)
|
|
|
|
|
|
{
|
|
|
|
|
|
var systems = doc.OfClass<MechanicalSystem>().Cast<MechanicalSystem>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var system in systems)
|
|
|
|
|
|
{
|
|
|
|
|
|
var elems = system.DuctNetwork;
|
|
|
|
|
|
foreach (Element elem in elems)
|
|
|
|
|
|
{
|
|
|
|
|
|
var id = InsulationLiningBase.GetInsulationIds(doc, elem.Id).FirstOrDefault();
|
|
|
|
|
|
if (id == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//风管或风管管件
|
|
|
|
|
|
if (elem is Duct duct ||
|
|
|
|
|
|
(elem is FamilyInstance instance &&
|
|
|
|
|
|
instance.Category.Id.IntegerValue == -2008010))
|
|
|
|
|
|
{
|
|
|
|
|
|
Autodesk.Revit.DB.Mechanical.DuctInsulation
|
|
|
|
|
|
.Create(
|
|
|
|
|
|
doc,
|
|
|
|
|
|
elem.Id,
|
|
|
|
|
|
DuctInsulationItem.DuctInsulationType.Id,
|
|
|
|
|
|
DuctInsulationItem.Thickness / 304.8);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var insulation = doc.GetElement(id) as DuctInsulation;
|
|
|
|
|
|
insulation.ChangeTypeId(DuctInsulationItem.DuctInsulationType.Id);
|
|
|
|
|
|
insulation.Thickness = DuctInsulationItem.Thickness / 304.8;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (AddToPipe)
|
|
|
|
|
|
{
|
|
|
|
|
|
var systems = doc.OfClass<PipingSystem>().Cast<PipingSystem>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var system in systems)
|
|
|
|
|
|
{
|
|
|
|
|
|
var elems = system.PipingNetwork;
|
|
|
|
|
|
foreach (Element elem in elems)
|
|
|
|
|
|
{
|
|
|
|
|
|
//水管或水管管件
|
|
|
|
|
|
if (elem is Pipe pipe ||
|
|
|
|
|
|
(elem is FamilyInstance instance &&
|
|
|
|
|
|
instance.Category.Id.IntegerValue == -2008049))
|
|
|
|
|
|
{
|
|
|
|
|
|
InsulationItem pipeInsulation = default;
|
|
|
|
|
|
foreach (var item in PipeInsulationItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
//直径
|
|
|
|
|
|
var str = elem.get_Parameter(BuiltInParameter.RBS_CALCULATED_SIZE)
|
|
|
|
|
|
.AsString()
|
|
|
|
|
|
.Split(' ')
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (double.TryParse(str, out var d))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (d >= item.MinDiameter && d <= item.MaxDiameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
pipeInsulation = item;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var id = InsulationLiningBase.GetInsulationIds(doc, elem.Id).FirstOrDefault();
|
|
|
|
|
|
if (id == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pipeInsulation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Autodesk.Revit.DB.Plumbing.PipeInsulation
|
|
|
|
|
|
.Create(
|
|
|
|
|
|
doc,
|
|
|
|
|
|
elem.Id,
|
|
|
|
|
|
pipeInsulation.PipeInsulationType.Id,
|
|
|
|
|
|
pipeInsulation.Thickness / 304.8);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var insulation = doc.GetElement(id) as PipeInsulation;
|
|
|
|
|
|
insulation.ChangeTypeId(pipeInsulation.PipeInsulationType.Id);
|
|
|
|
|
|
insulation.Thickness = pipeInsulation.Thickness / 304.8;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, "添加保温层");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//private bool CanAdd()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return (AddToDuct && SelectedDuctSystem != null) || (AddToPipe && SelectedPipingSystemType != null);
|
|
|
|
|
|
//}
|
|
|
|
|
|
private bool CanAdd => (AddToDuct && SelectedDuctSystem != null) ||
|
|
|
|
|
|
(AddToPipe && SelectedPipingSystemType != null);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有风管保温层类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<DuctInsulationType> DuctInsulationTypes { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有风管系统类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<MechanicalSystemType> DuctSystemTypes { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有管道保温层类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<PipeInsulationType> PipeInsulationTypes { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有管道系统类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<PipingSystemType> PipingSystemTypes { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|