• 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;
            }
        }
    }
  • 相关阅读:
    Objective-C 学习记录--toches、Motion/Size/Rect/Point/CGFloat/protocol
    Objective-C 学习记录6--dictionary
    Objc基础学习记录5
    第四篇:web之前端之jquery
    第三篇:web之前端之JavaScript基础
    第二篇:web之前端之css
    第一篇:web之前端之html
    第三篇:杂项之年终总结
    第二篇:杂项之图像处理pillow
    第一篇:杂项之pymysql连接池
  • 原文地址:https://www.cnblogs.com/xpvincent/p/3607629.html
Copyright © 2020-2023  润新知