Revit SDK 介绍:DisplacementElementAnimation

该博客介绍了如何使用Revit的置换图元功能创建动画。通过过滤不同类型的结构构件,如基础、结构框架、楼板、墙体和结构柱,为每个构件创建置换图元,并利用Idling事件和定时器更新图元位置,从而实现动态效果。示例代码展示了DisplacementElement的创建和管理过程。
摘要由CSDN通过智能技术生成

前言

这个例子介绍了如何用 Revit 的置换图元功能做动画。

内容

什么是置换图元?

在这里插入图片描述
置换图元仅仅是用来显示的,不会修改原始构件。
通过它可以为各个构件创建一个置换图元,可以通过修改图元的位置,达到下面的效果。
在这里插入图片描述
选中通过 RevitLookup 可以看到,置换图元有自己的类型,DisplacementElement:
在这里插入图片描述

SDK 的例子

效果

在这里插入图片描述
例子中只针对五种类型的结构构件做了处理:

BuiltInCategory.OST_StructuralFoundation
BuiltInCategory.OST_StructuralFraming
BuiltInCategory.OST_Floors
BuiltInCategory.OST_Walls
BuiltInCategory.OST_StructuralColumns

主要逻辑

步骤:

  1. 分别过滤出五类结构构件
  2. 为每类构件创建置换图元
  3. 注册 Revit 的 Idling 事件以及 timer 事件
  4. 通过上述两个事件对置换图元的位置进行更新

创建 DisplacementElement

接口:DisplacementElement.Create
创建置换图元,注意可以设置父子关系:

private void BuildDisplacementElementGroup(Document doc, ICollection<ElementId> ids, View view)
{
   // The last element will be in the "parent" displacement element.  (At least one element
   // must remain assigned to the parent, so all child displacements will be relative to the 
   // parent's displacement.)
   Element lastElement = doc.GetElement(ids.Last<ElementId>());
   XYZ parentDisplacedLocation = GetDisplacementXYFor(lastElement, XYZ.Zero);
   parentDisplacedLocation = MoveToElevation(parentDisplacedLocation, initialHeight);

   // All elements are added to the parent displacement element. 
   DisplacementElement parent = DisplacementElement.Create(doc, ids, parentDisplacedLocation, view, null);
   m_displacementElements.Add(parent);

   int count = ids.Count;
   List<ElementId> childIds = new List<ElementId>();
   List<ElementId> idsList = ids.ToList<ElementId>();

   // Add all elements except the last one to child displacement elements
   for (int index = 0; index < count - 1; index++)
   {
      ElementId childId = idsList[index];
      Element e = doc.GetElement(childId);

      XYZ displacedLocation = GetDisplacementXYFor(e, parentDisplacedLocation);

      // Setup id container for child DisplacementElement creation
      childIds.Clear();
      childIds.Add(childId);
      DisplacementElement child = DisplacementElement.Create(doc, childIds, displacedLocation, view, parent);
   }
   view.HideElements(ids);
}

其他逻辑可以参考源码:Revit 2021 SDK\Samples\DisplacementElementAnimation\CS\DisplacementStructureModelAnimator.cs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客BIM工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值