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

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Revit中,Transform是一种用于移动、旋转和镜像元素的操作。可以使用ElementTransformUtils类的方法来移动元素,例如使用MoveElement方法来移动单个元素,或者使用MoveElements方法来移动多个元素。这些方法需要传入一个向量参数,表示元素在三维空间中的移动方向和距离。\[1\]\[2\] 需要注意的是,基于标高的元素不能改变其Z轴坐标值,即不能向上或向下移动,但可以在同一标高内的任意位置移动元素。当移动一个元素时,可能会影响到其他与之相关联的元素,例如移动墙时,墙上的窗户也会跟着移动。如果元素被钉住(即Pinned属性为true),则表示该元素不能被移动。\[2\] 在Revit中,还可以使用向量来表示方向。向量是一个包含距离和方向的XYZ值,例如XYZ.BasisY表示向上的方向,XYZ.BasisX表示向右的方向。可以使用向量进行一些操作,例如将一个点移动到另一个点,计算两个点的中心点,或者计算两个点之间的向量。\[2\] 总结来说,Revit中的Transform操作可以通过ElementTransformUtils类的方法来实现,使用向量来表示移动的方向和距离。这些操作可以用于移动、旋转和镜像元素。\[1\]\[2\] #### 引用[.reference_title] - *1* *2* [revit编辑元素](https://blog.csdn.net/weixin_45574815/article/details/122981531)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Revit二开之Transform](https://blog.csdn.net/KiterPAN/article/details/127038003)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值