Revit二次開發,基於圖元中心點,批量旋轉指定角度

Revit二次開發,基於圖元中心點,批量旋轉指定角度


如上圖,有時候,我們需要對圖元批量旋轉指定角度,並且從圖元的中心點旋轉。

他的原理是使用api:ElementTransformUtils,可以實現您的意圖,api詳情如下:

<code>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 elemIds);
        public static ICollection CopyElement(Document document, ElementId elementToCopy, XYZ translation);
        public static ICollection CopyElements(View sourceView, ICollection elementsToCopy, View destinationView, Transform additionalTransform, CopyPasteOptions options);
        public static ICollection CopyElements(Document sourceDocument, ICollection elementsToCopy, Document destinationDocument, Transform transform, CopyPasteOptions options);
        public static ICollection CopyElements(Document document, ICollection elementsToCopy, XYZ translation);
        public static Transform GetTransformFromViewToView(View sourceView, View destinationView);
        public static void MirrorElement(Document document, ElementId elementToMirror, Plane plane);
        public static IList MirrorElements(Document document, ICollection elementsToMirror, Plane plane, bool mirrorCopies);
        public static void MoveElement(Document document, ElementId elementToMove, XYZ translation);
        public static void MoveElements(Document document, ICollection elementsToMove, XYZ translation);
        public static void RotateElement(Document document, ElementId elementToRotate, Line axis, double angle);
        public static void RotateElements(Document document, ICollection elementsToRotate, Line axis, double angle);
    }
}/<code>
Revit二次開發,基於圖元中心點,批量旋轉指定角度

本文用到的是這個方法:

Revit二次開發,基於圖元中心點,批量旋轉指定角度

具體實現代碼如下:

<code>/// 
/// 旋轉
/// 
/// 
private void Rotate(IList 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);
    }
}/<code>
Revit二次開發,基於圖元中心點,批量旋轉指定角度

界面如下圖:

Revit二次開發,基於圖元中心點,批量旋轉指定角度

當您點擊確定後,需要您選擇圖元,圖元數量不限,多選。然後如下圖,點擊完成即可實現:

Revit二次開發,基於圖元中心點,批量旋轉指定角度

源碼下載地址:https://download.csdn.net/download/mazhiyuan1981/12901583


分享到:


相關文章: