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;
}
}
}
上一篇:第一百五十八节,封装库--JavaScript,ajax说明


下一篇:Revit二次开发示例:ModelessForm_ExternalEvent