• Revit二次开发示例:DesignOptions


    本例只要演示Revit的类过滤器的用法,在对话框中显示DesignOption元素。

    #region Namespaces
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.Attributes;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.UI.Selection;
    #endregion
    
    namespace DesignOptionReader
    {
        [Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
        [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
        [Autodesk.Revit.Attributes.Journaling(JournalingMode.NoCommandData)]
        public class Command : IExternalCommand
        {
            public Result Execute(
              ExternalCommandData commandData,
              ref string message,
              ElementSet elements)
            {
                try
                {
                    Application application = commandData.Application.Application;
                    ElementClassFilter filter = new ElementClassFilter(typeof(Autodesk.Revit.DB.DesignOption));
                    FilteredElementCollector collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document);
                    collector.WherePasses(filter);
                    IEnumerator iter = collector.GetElementIdIterator();
                    Element element;
                    ElementSet designOptions = new ElementSet();
    
                    while (iter.MoveNext())
                    {
                        element = iter.Current as Element;
                        if (element.GetType().Equals(typeof(Autodesk.Revit.DB.DesignOption)))
                        {
                            designOptions.Insert(element);
                        }
                    }
    
                    if (designOptions.Size > 0)
                    {
                        DesignOptionsDialog dialog = new DesignOptionsDialog();
    
                        foreach (Element elem in designOptions)
                        {
                            dialog.DesignOptionsList.Items.Add(elem.Name);
                  
                        }
                        dialog.ShowDialog();
                    }
                    else
                    {
                        TaskDialog.Show("DesignOptions","There are no design options in this document");
                    }
    
                    
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    return Result.Failed;
                }
    
                return Result.Succeeded;
            }
        }
    }
  • 相关阅读:
    ArrayList和CopyOnWriteArrayList
    UML类关系
    Vmware下mint os的安装
    Java VisualVM无法检测到本地java程序 的 解决办法
    谜之闭包
    虚拟DOM(Virtual DOM)
    ES6箭头函数与普通函数的区别
    HTML中 select 与datalist的异同
    备战前端面试
    javascript获取数组中的最大值/最小值
  • 原文地址:https://www.cnblogs.com/xpvincent/p/3607629.html
Copyright © 2020-2023  润新知