首页 > 其他 > 详细

Revit二次开发示例:DesignOptions

时间:2014-03-18 14:41:32      阅读:477      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
#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;
        }
    }
}
bubuko.com,布布扣

Revit二次开发示例:DesignOptions,布布扣,bubuko.com

Revit二次开发示例:DesignOptions

原文:http://www.cnblogs.com/xpvincent/p/3607629.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!