EaBIM

标题: 根据共享参数来过滤满足条件的对象(代码) [打印本页]

作者: 萧闫子    时间: 2014-1-15 12:58
标题: 根据共享参数来过滤满足条件的对象(代码)
我们经常会添加自己的参数到对象中,一个参数可以添加到多个类别的对象。2011提供的过滤功能可以用参数的值来进行过滤。
下面代码可以对自定义参数按照参数值进行过滤。


  1. <p><font color="#333333" face="Arial"><span style="line-height: 26px;"></span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">
  2. </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">[c-sharp] view plaincopy</span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using System;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using System.Collections.Generic;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using System.Text;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">//using System.Windows.Forms;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using  Autodesk.Revit .DB;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using Autodesk.Revit.UI;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using Autodesk.Revit .ApplicationServices;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">using Autodesk.Revit.Attributes ;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  [RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)]  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">    public class ParamFilterTest : IExternalCommand  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">    {  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">      public Result Execute(  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        ExternalCommandData commandData,  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        ref string message,  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        ElementSet elements)  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">      {  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        UIApplication uiapp = commandData.Application;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        UIDocument uidoc = uiapp.ActiveUIDocument;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        Application app = uiapp.Application;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        Document doc = uidoc.Document;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        Wall wall = uidoc.Selection.PickObject(  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          Autodesk.Revit.UI.Selection.ObjectType.Element)  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          .Element as Wall;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        Parameter parameter = wall.get_Parameter(  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          "MyShared");  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        ParameterValueProvider pvp  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          = new ParameterValueProvider(parameter.Id);          </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        FilterStringEquals strEquals = new FilterStringEquals();  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        FilterStringRule sRule = new FilterStringRule(pvp, strEquals, "MyValue", true);  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        ElementParameterFilter filter  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          = new ElementParameterFilter(sRule);  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        FilteredElementCollector collector  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">          = new FilteredElementCollector(doc);  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        collector.WherePasses(filter);  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        TaskDialog.Show("count", collector.ToElementIds().Count.ToString());  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">        return Result.Succeeded;  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">      }  </span></font></p><p><font color="#333333" face="Arial"><span style="line-height: 26px;">    }  </span></font></p>
复制代码
作者:叶雄进文章来源:http://blog.csdn.net/joexiongjin/article/category/782739



作者: 龙龙..!    时间: 2014-2-20 14:10
顶!!!!!!!!!!!!!!!!!!!!!!!!!




欢迎光临 EaBIM (https://eabim.net/) Powered by Discuz! X3.2