• Revit SDK:WorkThread 做工的线程


    前言

    这个例子介绍了利用 idling 事件,在事件处理中利用 Analysis Visualisation Framework (AVF) 分析可视化框架来更新墙的一个面的颜色。

    内容

    实现的效果:
    在这里插入图片描述

    这个例子有两个个关键点:

    1. idling event + thread
    2. Analysis Visualisation Framework (AVF)

    核心逻辑1 - idling handler

    通过 uiapp.Idling 注册一个事件处理函数:

    m_hIdling = new EventHandler<IdlingEventArgs>(IdlingHandler);
    uiapp.Idling += m_hIdling;
    
    • 1
    • 2

    处理函数的核心是m_analyzer.UpdateResults:

    public void IdlingHandler(object sender, IdlingEventArgs args)
    {
    	bool processing = false;
    	if (m_analyzer != null)
    	{
    		UIApplication uiapp = sender as UIApplication;
    		if (uiapp.ActiveUIDocument != null)
    		{
    			using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document))
    			{
    				trans.Start("bogus transaction");
                    processing = m_analyzer.UpdateResults();
                    trans.Commit();
                }
    			// 通知 Revit 去进行更新
    			args.SetRaiseWithoutDelay();
    		}
    	}
    
    	// 如果分析结束,就取消注册消息处理函数
    	if (!processing)
    	{
    		UnsubscribeFromIdling(sender as UIApplication);
    		m_analyzer = null;
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    Analysis Visualisation Framework (AVF)

    Dynamo For Revit Node: Analysis Visualisation Framework (AVF) 分析可视化框架
    FaceAnalyzer 是通过启动另外一个线程,调用 AVF 框架让选中的墙面逐渐改变颜色。
    启动另外一个线程的逻辑,这个和多线程编程没有任何区别,它是通过m_analyzer.UpdateResults层层调用过来的:

    // Revit 2021 SDK\Samples\MultiThreading\WorkThread\CS\ThreadAgent.cs
    m_thread = new Thread(new ParameterizedThreadStart(this.Run));
    m_thread.Start(m_results);
    
    • 1
    • 2
    • 3

    在 Run 的方法里面做了AVF 需要的数据的更新。

    其它

    这个例子介绍的内容表明,在 Revit 的 idling 事件里面可以使用线程。但线程的使用肯定是有限制的,显然,我们不能在线程里面去改变 Revit 模型的内容。

  • 相关阅读:
    数据结构|栈和队列以及实现
    创建线程池的方法
    中国芯片金字塔成形,商业化拐点将至
    ChatGPT 现在可以看、听和说话了!
    条件分支和循环机制、标志寄存器及函数调用机制
    TikTok英国站的热门标签(二)
    softmax 与 sigmoid 关系测试
    底层驱动day8作业
    20 二叉查找树
    Linux 多线程( 进程VS线程 | 线程控制 )
  • 原文地址:https://blog.csdn.net/weixin_44153630/article/details/126356492