167 lines
6.2 KiB
C#
167 lines
6.2 KiB
C#
|
|
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
|
|||
|
|
using Autodesk.Revit.DB.Electrical;
|
|||
|
|
using Autodesk.Revit.DB.Mechanical;
|
|||
|
|
using Autodesk.Revit.DB.Plumbing;
|
|||
|
|
using Autodesk.Revit.UI.Selection;
|
|||
|
|
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
|
|||
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|||
|
|
|
|||
|
|
using System.Linq;
|
|||
|
|
|
|||
|
|
using Szmedi.RvKits.Assists;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RvKits.MEPTools
|
|||
|
|
{
|
|||
|
|
public partial class StandMepCurveViewModel : ObservableObject
|
|||
|
|
{
|
|||
|
|
public StandMepCurveViewModel(Document doc)
|
|||
|
|
{
|
|||
|
|
standMepCurveEventHandler = new ActionEventHandler();
|
|||
|
|
PipeTypes = doc.QueryElementsByType<PipeType>().Cast<PipeType>();
|
|||
|
|
DuctTypes = doc.QueryElementsByType<DuctType>().Cast<DuctType>();
|
|||
|
|
ConduitTypes = doc.QueryElementsByType<ConduitType>().Cast<ConduitType>();
|
|||
|
|
CableTrayTypes = doc.QueryElementsByType<CableTrayType>().Cast<CableTrayType>();
|
|||
|
|
PipeSystemTypes = doc.QueryElementsByType<PipingSystemType>().Cast<PipingSystemType>();
|
|||
|
|
DuctSystemTypes = doc.QueryElementsByType<MechanicalSystemType>().Cast<MechanicalSystemType>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private readonly ActionEventHandler standMepCurveEventHandler;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private System.Collections.IEnumerable cableTrayTypes;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private System.Collections.IEnumerable conduitTypes;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private System.Collections.IEnumerable ductSystemTypes;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private System.Collections.IEnumerable ductTypes;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private bool? isCableTray = false;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private bool? isConduit = false;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private bool? isDuct = false;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private bool? isPipe = true;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private System.Collections.IEnumerable pipeSystemTypes;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
private System.Collections.IEnumerable pipeTypes;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private CableTrayType selectedCableTrayType;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private ConduitType selectedConduitType;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private MechanicalSystemType selectedDuctSystemType;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private DuctType selectedDuctType;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private PipingSystemType selectedPipeSystemType;
|
|||
|
|
|
|||
|
|
[ObservableProperty]
|
|||
|
|
[NotifyCanExecuteChangedFor(nameof(CreateMepCurveCommand))]
|
|||
|
|
private PipeType selectedPipeType;
|
|||
|
|
private bool isRunning;
|
|||
|
|
|
|||
|
|
private bool CanCreate()
|
|||
|
|
{
|
|||
|
|
return (IsPipe == true && SelectedPipeType != null && SelectedPipeSystemType != null)
|
|||
|
|
|| (IsDuct == true && SelectedDuctType != null && SelectedDuctSystemType != null)
|
|||
|
|
|| (IsConduit == true && SelectedConduitType != null)
|
|||
|
|
|| (IsCableTray == true && SelectedCableTrayType != null && !isRunning);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void Cancel()
|
|||
|
|
{
|
|||
|
|
if (isRunning)
|
|||
|
|
{
|
|||
|
|
CommandAssists.ExitCurrentCommand();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand(CanExecute = nameof(CanCreate))]
|
|||
|
|
private void CreateMepCurve()
|
|||
|
|
{
|
|||
|
|
isRunning = true;
|
|||
|
|
standMepCurveEventHandler.Raise(app =>
|
|||
|
|
{
|
|||
|
|
var uidoc = app.ActiveUIDocument;
|
|||
|
|
var view = uidoc.ActiveView;
|
|||
|
|
var doc = uidoc.Document;
|
|||
|
|
var snapping = ObjectSnapTypes.Centers | ObjectSnapTypes.Tangents | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Endpoints | ObjectSnapTypes.Nearest | ObjectSnapTypes.Perpendicular | ObjectSnapTypes.Intersections;
|
|||
|
|
var point = uidoc.Selection.PickPoint(snapping, "创建立管的点");
|
|||
|
|
var startPoint = new XYZ(point.X, point.Y, view.GenLevel.Elevation);
|
|||
|
|
var endPoint = new XYZ(point.X, point.Y, view.GenLevel.Elevation + (2000 / 304.8));
|
|||
|
|
doc.Invoke(
|
|||
|
|
_ =>
|
|||
|
|
{
|
|||
|
|
if (IsPipe == true)
|
|||
|
|
{
|
|||
|
|
var pipe = Pipe.Create(
|
|||
|
|
doc,
|
|||
|
|
SelectedPipeSystemType.Id,
|
|||
|
|
SelectedPipeType.Id,
|
|||
|
|
view.GenLevel.Id,
|
|||
|
|
startPoint,
|
|||
|
|
endPoint
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
else if (IsDuct == true)
|
|||
|
|
{
|
|||
|
|
var duct = Duct.Create(
|
|||
|
|
doc,
|
|||
|
|
SelectedDuctSystemType.Id,
|
|||
|
|
SelectedDuctType.Id,
|
|||
|
|
view.GenLevel.Id,
|
|||
|
|
startPoint,
|
|||
|
|
endPoint
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
else if (IsConduit == true)
|
|||
|
|
{
|
|||
|
|
var conduit = Conduit.Create(doc, SelectedConduitType.Id, startPoint, endPoint, view.GenLevel.Id);
|
|||
|
|
}
|
|||
|
|
else if (IsCableTray == true)
|
|||
|
|
{
|
|||
|
|
var cableTray = CableTray.Create(doc, SelectedCableTrayType.Id, startPoint, endPoint, view.GenLevel.Id);
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
"创建立管"
|
|||
|
|
);
|
|||
|
|
});
|
|||
|
|
isRunning = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|