Revit二次开发,基于图元中心点,批量旋转指定角度

如上图,有时候,我们需要对图元批量旋转指定角度,并且从图元的中心点旋转。

他的原理是使用api:ElementTransformUtils,可以实现您的意图,api详情如下:

using System.Collections.Generic;

namespace Autodesk.Revit.DB
{
    public static class ElementTransformUtils
    {
        public static bool CanMirrorElement(Document ADoc, ElementId elemId);
        public static bool CanMirrorElements(Document ADoc, ICollection<ElementId> elemIds);
        public static ICollection<ElementId> CopyElement(Document document, ElementId elementToCopy, XYZ translation);
        public static ICollection<ElementId> CopyElements(View sourceView, ICollection<ElementId> elementsToCopy, View destinationView, Transform additionalTransform, CopyPasteOptions options);
        public static ICollection<ElementId> CopyElements(Document sourceDocument, ICollection<ElementId> elementsToCopy, Document destinationDocument, Transform transform, CopyPasteOptions options);
        public static ICollection<ElementId> CopyElements(Document document, ICollection<ElementId> elementsToCopy, XYZ translation);
        public static Transform GetTransformFromViewToView(View sourceView, View destinationView);
        public static void MirrorElement(Document document, ElementId elementToMirror, Plane plane);
        public static IList<ElementId> MirrorElements(Document document, ICollection<ElementId> elementsToMirror, Plane plane, bool mirrorCopies);
        public static void MoveElement(Document document, ElementId elementToMove, XYZ translation);
        public static void MoveElements(Document document, ICollection<ElementId> elementsToMove, XYZ translation);
        public static void RotateElement(Document document, ElementId elementToRotate, Line axis, double angle);
        public static void RotateElements(Document document, ICollection<ElementId> elementsToRotate, Line axis, double angle);
    }
}

本文用到的是这个方法:

具体实现代码如下:

/// <summary>
/// 旋转
/// </summary>
/// <param name="references"></param>
private void Rotate(IList<Reference> references)
{
    foreach (var reference in references)
    {
        var e = this._document.GetElement(reference);
        var locationPoint = e.Location as LocationPoint;
        if (locationPoint == null)
        {
            continue;
        }
        var point = locationPoint.Point;
        var axis = Autodesk.Revit.DB.Line.CreateBound(point, new XYZ(point.X, point.Y, point.Z + 1));
        var alpha = this._angle.ToRadian();
        ElementTransformUtils.RotateElement(this._document, reference.ElementId, axis, alpha);
    }
}

界面如下图:

当您点击确定后,需要您选择图元,图元数量不限,多选。然后如下图,点击完成即可实现:

源码下载地址:https://download.csdn.net/download/mazhiyuan1981/12901583

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值