添加项目文件。
This commit is contained in:
81
Sai.RvKits/RvMEP/RotateMEPViewModel.cs
Normal file
81
Sai.RvKits/RvMEP/RotateMEPViewModel.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
|
||||
namespace Sai.RvKits.RvMEP
|
||||
{
|
||||
public partial class RotateMEPViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private double angle;
|
||||
[ObservableProperty]
|
||||
private bool isSingleSelect = true;
|
||||
[RelayCommand]
|
||||
private void RotateInstance()
|
||||
{
|
||||
rotateHandler.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
var doc = uidoc.Document;
|
||||
ICollection<ElementId> elemIds = [];
|
||||
if (uidoc.Selection.GetElementIds().Any())
|
||||
{
|
||||
elemIds = uidoc.Selection.GetElementIds();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsSingleSelect)
|
||||
{
|
||||
var r = uidoc.Selection.PickObject(ObjectType.Element, new FuncFilter(e =>
|
||||
{
|
||||
return e is FamilyInstance && e.GetConnectors().OfType<Connector>().Any(c => c.IsConnected);
|
||||
}), "请选择可以连管的构件");
|
||||
|
||||
elemIds.Add(r.ElementId);
|
||||
}
|
||||
else
|
||||
{
|
||||
elemIds = uidoc.Selection.PickObjects(ObjectType.Element, new FuncFilter(e =>
|
||||
{
|
||||
return e is FamilyInstance && e.GetConnectors().OfType<Connector>().Any(c => c.IsConnected);
|
||||
}), "请选择可以连管的构件,并完成").Select(r => doc.GetElement(r).Id).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var id in uidoc.Selection.GetElementIds())
|
||||
{
|
||||
var elem = uidoc.Document.GetElement(id);
|
||||
|
||||
var referConn = elem.GetConnectors().OfType<Connector>().FirstOrDefault(c => c.IsConnected);
|
||||
|
||||
if (referConn != null)
|
||||
{
|
||||
doc.Invoke(
|
||||
ts =>
|
||||
{
|
||||
ElementTransformUtils.RotateElement(
|
||||
doc,
|
||||
elem.Id,
|
||||
Line.CreateUnbound(
|
||||
referConn.CoordinateSystem.Origin,
|
||||
referConn.CoordinateSystem.BasisZ),
|
||||
Angle.ToRadian());
|
||||
}, "旋转");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
readonly ActionEventHandler rotateHandler = new();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user