Revit SDK:DynamicModelUpdate 模型动态更新

前言

Revit API 提供了一些接口,用户可以在特定修改发生的时候,做一些额外的动作。

内容

这个例子的内容,注册更新器之后,当窗户的位置发生变化,对应的 section view 也会发生变化,保证它一直与窗户垂直,且经过窗户的中点。
在这里插入图片描述

核心逻辑

  1. FailureDefinitionId 用于定义错误的行为,职责:
    a. 标识一个错误
    b. 错误严重等级
    c. 默认的错误处理方法
    d. 特定场景的错误处理方法 - FailureResolution
    e. 通过自身的静态方法进行注册 - FailureDefinition.CreateFailureDefinition

  2. 错误处理的时机,Transaction 开始之前、之中和之后:
    a. 前处理 Transaction -> FailureHandlingOptions -> FailurePreproccessor
    b. 中处理 Application.FailuresProcessing
    c. 后处理 Transaction -> FailureHandlingOptions -> FailuresProcessor 或者 Application.RegisterFailuresProcessor

例子中列出的可能不全,Revit API 中可能还有其他地方可以进行错误处理。

注册更新器

// Autodesk.Revit.DB.UpdaterRegistry
public static void AddTrigger(UpdaterId id, Document document, ICollection<ElementId> elements, ChangeType change);

可能的变化类型 ChangeType , Element 增加、删除、几何变化和参数变化:

// Autodesk.Revit.DB.Element
public static ChangeType GetChangeTypeAny();
public static ChangeType GetChangeTypeElementAddition();
public static ChangeType GetChangeTypeElementDeletion();
public static ChangeType GetChangeTypeGeometry();
public static ChangeType GetChangeTypeParameter(ElementId parameterId);
public static ChangeType GetChangeTypeParameter(Parameter param);

例子中注册的逻辑,几何发生变化的时候触发:

internal void AddTriggerForUpdater(Document doc, List<ElementId> idsToWatch, ElementId sectionId, Element sectionElement)
{
    if (idsToWatch.Count == 0)
        return;

    m_windowId = idsToWatch[0];
    m_sectionId = sectionId;
    m_sectionElement = sectionElement;
    UpdaterRegistry.AddTrigger(m_updaterId, doc, idsToWatch, Element.GetChangeTypeGeometry());
}

AddTriggerForUpdater 这个接口并属于 IUpdater,是这个例子特有的:

namespace Autodesk.Revit.DB
{
    public interface IUpdater
    {
        void Execute(UpdaterData data);
        string GetAdditionalInformation();
        ChangePriority GetChangePriority();
        UpdaterId GetUpdaterId();
        string GetUpdaterName();
    }
}

SectionUpdater 的更新逻辑:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

极客BIM工作室

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

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

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

打赏作者

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

抵扣说明:

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

余额充值