本文演示如何通过代码,实现Revit中墙的移动,复制,旋转,镜像。
1.用Revit绘制墙
2.移动
ElementTransformUtils.MoveElement()实现移动功能。
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace RevitAddin3
{
[TransactionAttribute(TransactionMode.Manual)]
public class RevitAddin : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Selection selection = uiDoc.Selection;
var eleIds = selection.GetElementIds();
Transaction trans = new Transaction(doc);
trans.Start("Move");
foreach (var item in eleIds)
{
ElementTransformUtils.MoveElement(doc, item, new XYZ(10, 10, 0));
}
trans.Commit();
return Result.Succeeded;
}
}
}
执行结果:
3.复制
ElementTransformUtils.CopyElement实现复制功能。
ElementTransformUtils.CopyElement(doc, item, new XYZ(10, 10, 0));
执行结果:
4.旋转
ElementTransformUtils.RotateElement实现旋转功能。
ElementTransformUtils.RotateElement(doc, item, Line.CreateUnbound(new XYZ(0, 0, 0), new XYZ(0, 0, 1)), 45.0);
执行结果:
5.镜像
ElementTransformUtils.MirrorElement实现镜像功能。
ElementTransformUtils.MirrorElement(doc, item, Plane.CreateByNormalAndOrigin(new XYZ(1, 0, 0), new XYZ(-40, 0, 0)));
执行结果: