Пример #1
0
    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    {
        // Get application and document objects
        UIApplication uiApp = commandData.Application;
        Document doc = uiApp.ActiveUIDocument.Document;
        UIDocument uidoc = uiApp.ActiveUIDocument;

        try
        {
            using (Transaction trans = new Transaction(doc, "UpperCase Views on Sheets."))
            {
                // Delete all unnamed Reference Planes in the project
                // Create Filter to check for Name
                BuiltInParameter bip = BuiltInParameter.DATUM_TEXT;
                ParameterValueProvider provider = new ParameterValueProvider(new ElementId(bip));
                FilterStringEquals evaluator = new FilterStringEquals();
                FilterStringRule rule = new FilterStringRule(provider, evaluator, "", false);
                ElementParameterFilter filter = new ElementParameterFilter(rule);

                ICollection<ElementId> refPlanes = new FilteredElementCollector(doc)
                    .OfClass(typeof(ReferencePlane))
                    .WherePasses(filter)
                    .ToElementIds();

                int count = refPlanes.Count;
                try
                {
                    trans.Start();
                    doc.Delete(refPlanes);
                    trans.Commit();
                }
                catch (Exception x)
                {
                    message = x.Message;
                    return Result.Failed;
                }

                TaskDialog.Show("Delete Reference Planes", "You have successfully delete " + count.ToString() + " unnamed reference planes!");
                return Result.Succeeded;
            }
        }
        // Catch any Exceptions and display them.
        catch (Autodesk.Revit.Exceptions.OperationCanceledException)
        {
            return Result.Cancelled;
        }
        catch (Exception x)
        {
            message = x.Message;
            return Result.Failed;
        }
    }
Пример #2
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            try
            {
                uiApp = commandData.Application;
                uiDoc = uiApp.ActiveUIDocument;
                app = uiApp.Application;
                doc = uiDoc.Document;

                FilteredElementCollector refPlaneCollector = new FilteredElementCollector(doc);
                IList<Element> refPlanes = refPlaneCollector.OfClass(typeof(ReferencePlane)).ToElements();

                ElementId nameParamterId = new ElementId(BuiltInParameter.DATUM_TEXT);
                ParameterValueProvider pvp = new ParameterValueProvider(nameParamterId);
                FilterStringRuleEvaluator evaluator = new FilterStringEquals();
                FilterRule rule = new FilterStringRule(pvp, evaluator, "", false);
                ElementFilter filter = new ElementParameterFilter(rule);

                FilteredElementCollector unnamedRefPlaneCollector = new FilteredElementCollector(doc);
                unnamedRefPlaneCollector.OfClass(typeof(ReferencePlane));
                unnamedRefPlaneCollector.WherePasses(filter);
                IList<Element> unnamedRefPlanes = unnamedRefPlaneCollector.ToElements();

                Transaction transaction = new Transaction(doc);
                transaction.Start("Purging unnamed reference planes");

                foreach (Element refPlane in unnamedRefPlanes)
                     doc.Delete(refPlane.Id);

                transaction.Commit();

                TaskDialog.Show("Purge Unnamed Ref Planes",
                                String.Format("{0} reference planes found.\n{1} unnamed reference planes deleted.",
                                               refPlanes.Count.ToString(), unnamedRefPlanes.Count.ToString()));

                return Result.Succeeded;
            }
            catch (Exception e)
            {
                TaskDialog.Show("Revit Quick Tools", e.Message);
                return Result.Failed;
            }
        }
        /// <summary>
        /// Return the all elements that
        /// use the given ElementType.
        /// </summary>
        static FilteredElementCollector GetAllElementsUsingType(
            Document doc,
            ElementType et)
        {
            // built-in parameter storing the type element id:

              BuiltInParameter bip
            = BuiltInParameter.ELEM_TYPE_PARAM;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterNumericRuleEvaluator evaluator
            = new FilterNumericEquals();

              FilterRule rule = new FilterElementIdRule(
            provider, evaluator, et.Id );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              FilteredElementCollector collector
            = new FilteredElementCollector( doc )
              .WhereElementIsNotElementType()
              .WherePasses( filter );

              return collector;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string messages,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              Transaction tx = new Transaction( doc, "Test" );
              tx.Start();

              // use the view filter

              FilteredElementCollector collector
            = new FilteredElementCollector(
              doc, doc.ActiveView.Id );

              // use the parameter filter.
              // get the phase id "New construction"

              ElementId idPhase = GetPhaseId(
            "New Construction", doc );

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( (int)
            BuiltInParameter.PHASE_CREATED ) );

              FilterNumericRuleEvaluator evaluator
            = new FilterNumericEquals();

              FilterElementIdRule rule
            = new FilterElementIdRule(
              provider, evaluator, idPhase );

              ElementParameterFilter parafilter
            = new ElementParameterFilter( rule );

              collector.WherePasses( parafilter );

              TaskDialog.Show( "Element Count",
            "There are " + collector.Count().ToString()
            + " elements in the current view created"
            + " with phase New Construction" );

              tx.Commit();

              return Result.Succeeded;
        }
            public Result Execute(
                ExternalCommandData commandData,
                ref string messages,
                ElementSet elements)
            {
                UIApplication app = commandData.Application;
                Document doc = app.ActiveUIDocument.Document;

                ElementId id = new ElementId(
                  BuiltInParameter.ELEM_ROOM_NUMBER );

                ParameterValueProvider provider
                  = new ParameterValueProvider( id );

                FilterStringRuleEvaluator evaluator
                  = new FilterStringEquals();

                string sRoomNumber = "1";

                FilterRule rule = new FilterStringRule(
                  provider, evaluator, sRoomNumber, false );

                ElementParameterFilter filter
                  = new ElementParameterFilter( rule );

                FilteredElementCollector collector
                  = new FilteredElementCollector( doc );

                string s = string.Empty;

                foreach( Element e in collector )
                {
                  s += e.Name + e.Category.Name.ToString() + "\n";

                }
                System.Windows.Forms.MessageBox.Show( s );

                return Result.Succeeded;
            }
        /// <summary>
        /// Retrieve all stairs on a given level.
        /// </summary>
        FilteredElementCollector GetStairsOnLevel(
            Document doc,
            Level level)
        {
            ElementId id = level.Id;

              BuiltInCategory bic
            = BuiltInCategory.OST_Stairs;

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfCategory( bic );

              // explicit iteration and manual
              // checking of a property:

              List<Element> stairs = new List<Element>();

              foreach( Element e in collector )
              {
            if( e.LevelId.Equals( id ) )
            {
              stairs.Add( e );
            }
              }

              // using LINQ:

              IEnumerable<Element> stairsOnLevelLinq =
            from e in collector
            where e.LevelId.Equals( id )
            select e;

              // using an anonymous method:

              IEnumerable<Element> stairsOnLevelAnon =
            collector.Where<Element>( e
              => e.LevelId.Equals( id ) );

              // using a parameter filter:

              BuiltInParameter bip
            = BuiltInParameter.STAIRS_BASE_LEVEL_PARAM;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterNumericRuleEvaluator evaluator
            = new FilterNumericEquals();

              FilterRule rule = new FilterElementIdRule(
            provider, evaluator, id );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              return collector.WherePasses( filter );
        }
    private static void HostedFamilyInstanceOpenings(Wall wall,
        double minOpeningValue)
    {
      double wallOpeningArea = 0.0;
      double wallTotalOpeningArea = 0.0;

      // Filter all Family Instances where the HOST_ID_PARAM 
      // equals the wall ID
      // 
      // More information at
      // http://thebuildingcoder.typepad.com/
      //                 blog/2010/06/parameter-filter.html#4
      BuiltInParameter testParam =
          BuiltInParameter.HOST_ID_PARAM;
      ParameterValueProvider pvp =
          new ParameterValueProvider(
              new ElementId((int)testParam));

      FilterNumericRuleEvaluator fnrv = new FilterNumericEquals();
      ElementId ruleValId = wall.Id;

      FilterRule paramFr = new FilterElementIdRule
        (pvp, fnrv, ruleValId);
      ElementParameterFilter epf = 
        new ElementParameterFilter(paramFr);
      FilteredElementCollector collector =
          new FilteredElementCollector(wall.Document);

      collector.OfClass(typeof(FamilyInstance)).WherePasses(epf);
      IList<Element> hostedFamilyInstances = collector.ToElements();

      // Now iterate through the collected family instances
      Document doc = wall.Document;
      double previousArea = wall.get_Parameter(
          BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();

      foreach (FamilyInstance instance in hostedFamilyInstances)
      {
        // Delete the hosted family instace and regenerate
        doc.Delete(instance);
        doc.Regenerate();

        // Get the new area to compare
        double newArea = wall.get_Parameter(
            BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();

        // So the instance opening equals:
        double instanceAreaOnTheWall = 
          Math.Abs(newArea - previousArea);

        // The element area (on wall) is smaller than 
        // the minOpeningValue?
        if (instanceAreaOnTheWall <= minOpeningValue)
          wallOpeningArea += instanceAreaOnTheWall;
        else
          wallTotalOpeningArea += instanceAreaOnTheWall;

        if (System.Diagnostics.Debugger.IsAttached)
          TaskDialog.Show(
              "Wall opening (by inst) found (in sq feet)",
              string.Format("Area: {0}", instanceAreaOnTheWall));

        previousArea = newArea;
      }

      AddWallArea(wall.Id, wallOpeningArea, wallTotalOpeningArea);
    }
    /// <summary>
    /// Optional - example of parameter filter. 
    /// Find walls whose length is longer than a certain length. e.g., 60 feet 
    ///     wall.parameter(length) > 60 feet 
    /// This could get more complex than looping through in terms of writing a code. 
    /// See page 87 of Developer guide. 
    /// </summary> 
    public IList<Element> FindLongWalls()
    {
      // Constant for this function. 
      const double kWallLength = 60.0;  // 60 feet. hard coding for simplicity. 

      // First, narrow down to the elements of the given type and category 
      var collector = new FilteredElementCollector(_doc).OfClass(typeof(Wall));

      // Define a filter by parameter 
      // 1st arg - value provider 
      BuiltInParameter lengthParam = BuiltInParameter.CURVE_ELEM_LENGTH;
      int iLengthParam = (int)lengthParam;
      var paramValueProvider = new ParameterValueProvider(new ElementId(iLengthParam));

      // 2nd - evaluator 
      FilterNumericGreater evaluator = new FilterNumericGreater();

      // 3rd - rule value 
      double ruleVal = kWallLength;

      // 4th - epsilon 
      const double eps = 1E-06;

      // Define a rule 
      var filterRule = new FilterDoubleRule(paramValueProvider, evaluator, ruleVal, eps);

      // Create a new filter 
      var paramFilter = new ElementParameterFilter(filterRule);

      // Go through the filter 
      IList<Element> elems = collector.WherePasses(paramFilter).ToElements();

      return elems;
    }
        void f3( Document doc )
        {
            FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfClass( typeof( Level ) );
              ElementId id = new ElementId(
            BuiltInParameter.DATUM_TEXT );

              ParameterValueProvider provider
            = new ParameterValueProvider( id );

              FilterStringRuleEvaluator evaluator
            = new FilterStringContains();

              FilterRule rule = new FilterStringRule(
            provider, evaluator, "Level", false );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Application app = uiapp.Application;
              Document doc = uidoc.Document;

              // Construct a parameter filter to get only
              // unnamed reference planes, i.e. reference
              // planes whose name equals the empty string:

              BuiltInParameter bip
            = BuiltInParameter.DATUM_TEXT;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterStringRuleEvaluator evaluator
            = new FilterStringEquals();

              FilterStringRule rule = new FilterStringRule(
            provider, evaluator, "", false );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              FilteredElementCollector col
            = new FilteredElementCollector( doc )
              .OfClass( typeof( ReferencePlane ) )
              .WherePasses( filter );

              int n = 0;
              int nDeleted = 0;

              // No need to cast ... this is pretty nifty,
              // I find ... grab the elements as ReferencePlane
              // instances, since the filter guarantees that
              // only ReferencePlane instances are selected.
              // In Revit 2014, this attempt to delete the
              // reference planes while iterating over the
              // filtered element collector throws an exception:
              // Autodesk.Revit.Exceptions.InvalidOperationException:
              // HResult=-2146233088
              // Message=The iterator cannot proceed due to
              // changes made to the Element table in Revit's
              // database (typically, This can be the result
              // of an Element deletion).
              //
              //foreach( ReferencePlane rp in col )
              //{
              //  ++n;
              //  nDeleted += DeleteIfNotHosting( rp ) ? 1 : 0;
              //}

              ICollection<ElementId> ids = col.ToElementIds();

              n = ids.Count();

              if( 0 < n )
              {
            using( Transaction tx = new Transaction( doc ) )
            {
              tx.Start( string.Format(
            "Delete {0} ReferencePlane{1}",
            n, Util.PluralSuffix( n ) ) );

              // This also causes the exception "One or more of
              // the elementIds cannot be deleted. Parameter
              // name: elementIds
              //
              //ICollection<ElementId> ids2 = doc.Delete(
              //  ids );
              //nDeleted = ids2.Count();

              List<ElementId> ids2 = new List<ElementId>(
            ids );

              foreach( ElementId id in ids2 )
              {
            try
            {
              ICollection<ElementId> ids3 = doc.Delete(
                id );

              nDeleted += ids3.Count;
            }
            catch( Autodesk.Revit.Exceptions.ArgumentException )
            {
            }
              }

              tx.Commit();
            }
              }

              Util.InfoMsg( string.Format(
            "{0} unnamed reference plane{1} examined, "
            + "{2} element{3} in total were deleted.",
            n, Util.PluralSuffix( n ),
            nDeleted, Util.PluralSuffix( nDeleted ) ) );

              return Result.Succeeded;
        }
        /// <summary>
        /// Return the first wall found that
        /// uses the given wall type.
        /// </summary>
        static Wall GetFirstWallUsingType(
            Document doc,
            WallType wallType)
        {
            // built-in parameter storing this
              // wall's wall type element id:

              BuiltInParameter bip
            = BuiltInParameter.ELEM_TYPE_PARAM;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterNumericRuleEvaluator evaluator
            = new FilterNumericEquals();

              FilterRule rule = new FilterElementIdRule(
            provider, evaluator, wallType.Id );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              FilteredElementCollector collector
            = new FilteredElementCollector( doc )
              .OfClass( typeof( Wall ) )
              .WherePasses( filter );

              return collector.FirstElement() as Wall;
        }
        /// <summary>
        /// Return the first wall type with the given name.
        /// </summary>
        static WallType GetFirstWallTypeNamed(
            Document doc,
            string name)
        {
            // built-in parameter storing this
              // wall type's name:

              BuiltInParameter bip
            = BuiltInParameter.SYMBOL_NAME_PARAM;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterStringRuleEvaluator evaluator
            = new FilterStringEquals();

              FilterRule rule = new FilterStringRule(
            provider, evaluator, name, false );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              FilteredElementCollector collector
            = new FilteredElementCollector( doc )
              .OfClass( typeof( WallType ) )
              .WherePasses( filter );

              return collector.FirstElement() as WallType;
        }
        /// <summary>
        /// Return all elements from the given collector
        /// whose element id is greater than 'lastId'.
        /// </summary>
        FilteredElementCollector GetElementsAfter(
            FilteredElementCollector input,
            ElementId lastId)
        {
            BuiltInParameter bip = BuiltInParameter.ID_PARAM;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterNumericRuleEvaluator evaluator
            = new FilterNumericGreater();

              FilterRule rule = new FilterElementIdRule(
            provider, evaluator, lastId );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              return input.WherePasses( filter );
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Application app = uiapp.Application;
              Document doc = uidoc.Document;

              Reference r = uidoc.Selection.PickObject(
            ObjectType.Element );

              // 'Autodesk.Revit.DB.Reference.Element' is
              // obsolete: Property will be removed. Use
              // Document.GetElement(Reference) instead.
              //Wall wall = r.Element as Wall; // 2011

              Wall wall = doc.GetElement( r ) as Wall; // 2012

              Parameter parameter = wall.get_Parameter(
            "Unconnected Height" );

              ParameterValueProvider pvp
            = new ParameterValueProvider( parameter.Id );

              FilterNumericRuleEvaluator fnrv
            = new FilterNumericGreater();

              FilterRule fRule
            = new FilterDoubleRule( pvp, fnrv, 20, 1E-6 );

              ElementParameterFilter filter
            = new ElementParameterFilter( fRule );

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              // Find walls with unconnected height
              // less than or equal to 20:

              ElementParameterFilter lessOrEqualFilter
            = new ElementParameterFilter( fRule, true );

              IList<Element> lessOrEqualFounds
            = collector.WherePasses( lessOrEqualFilter )
              .OfCategory( BuiltInCategory.OST_Walls )
              .OfClass( typeof( Wall ) )
              .ToElements();

              TaskDialog.Show( "Revit", "Walls found: "
            + lessOrEqualFounds.Count );

              return Result.Succeeded;
        }
        /// <summary>
        /// Return a list of all elements with the 
        /// specified value in their shared parameter with 
        /// the given name oand group. They are retrieved
        /// using a parameter filter, and the required 
        /// parameter id is found by temporarily adding 
        /// the shared parameter to the project info.
        /// </summary>
        static IList<Element> GetElementsMatchingParameter(
            Document doc,
            string paramName,
            string paramGroup,
            string paramValue)
        {
            IList<Element> elems = new List<Element>();

              // Determine if definition for parameter binding exists

              Definition definition = null;
              BindingMap bm = doc.ParameterBindings;
              DefinitionBindingMapIterator it = bm.ForwardIterator();
              while( it.MoveNext() )
              {
            Definition def = it.Key;
            if( def.Name.Equals( paramName ) )
            {
              definition = def;
              break;
            }
              }
              if( definition == null )
              {
            return elems; // parameter binding not defined
              }

              using( Transaction tx = new Transaction( doc ) )
              {
            tx.Start( "Set temporary parameter" );

            // Temporarily set project information element
            // parameter in order to determine param.Id

            FilteredElementCollector collectorPI
              = new FilteredElementCollector( doc );

            collectorPI.OfCategory(
              BuiltInCategory.OST_ProjectInformation );

            Element projInfoElem
              = collectorPI.FirstElement();

            // using http://thebuildingcoder.typepad.com/blog/2012/04/adding-a-category-to-a-shared-parameter-binding.html

            Parameter param = null;

            //param = HelperParams.GetOrCreateElemSharedParam(
            //     projInfoElem, paramName, paramGroup,
            //     ParameterType.Text, false, true );

            if( param != null )
            {
              ElementId paraId = param.Id;

              tx.RollBack(); // discard project element change

              ParameterValueProvider provider
            = new ParameterValueProvider( paraId );

              FilterRule rule = new FilterStringRule(
            provider, new FilterStringEquals(),
            paramValue, true );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              FilteredElementCollector collector
            = new FilteredElementCollector(
              doc, doc.ActiveView.Id );

              elems = collector.WherePasses( filter )
            .ToElements();
            }
              }
              return elems;
        }
        void f2( Document doc, Level level )
        {
            FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfCategory(
            BuiltInCategory.OST_StructuralFraming );

              collector.OfClass( typeof( FamilyInstance ) );

              BuiltInParameter bip = BuiltInParameter
            .INSTANCE_REFERENCE_LEVEL_PARAM;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterNumericRuleEvaluator evaluator
            = new FilterNumericGreater();

              ElementId idRuleValue = level.Id;

              FilterElementIdRule rule
            = new FilterElementIdRule(
              provider, evaluator, idRuleValue );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              collector.WherePasses( filter );
        }
        void f4( Document doc )
        {
            // Use numeric evaluator and integer rule to test ElementId parameter
              // Filter levels whose id is greater than specified id value

              BuiltInParameter testParam
            = BuiltInParameter.ID_PARAM;

              ParameterValueProvider pvp
            = new ParameterValueProvider(
              new ElementId( (int) testParam ) );

              FilterNumericRuleEvaluator fnrv
            = new FilterNumericGreater();

              // filter elements whose Id is greater than 99

              ElementId ruleValId = new ElementId( 99 );

              FilterRule paramFr = new FilterElementIdRule(
            pvp, fnrv, ruleValId );

              ElementParameterFilter epf
            = new ElementParameterFilter( paramFr );

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfClass( typeof( ViewPlan ) )
            .WherePasses( epf ); // only deal with ViewPlan

              // Use numeric evaluator and integer rule to test bool parameter
              // Filter levels whose crop view is false

              int ruleValInt = 0;

              testParam = BuiltInParameter.VIEWER_CROP_REGION;

              pvp = new ParameterValueProvider(
            new ElementId( (int) testParam ) );

              fnrv = new FilterNumericEquals();

              paramFr = new FilterIntegerRule(
            pvp, fnrv, ruleValInt );

              epf = new ElementParameterFilter( paramFr );

              collector = new FilteredElementCollector( doc );

              collector.OfClass( typeof( ViewPlan ) )
            .WherePasses( epf ); // only deal with ViewPlan

              // Use numeric evaluator and double rule to test double parameter
              // Filter levels whose top offset is greater than specified value

              double ruleValDb = 10;

              testParam =
            BuiltInParameter.VIEWER_BOUND_OFFSET_TOP;

              pvp = new ParameterValueProvider(
            new ElementId( (int) testParam ) );

              fnrv = new FilterNumericGreater();

              paramFr = new FilterDoubleRule(
            pvp, fnrv, ruleValDb, double.Epsilon );

              collector = new FilteredElementCollector( doc );

              collector.OfClass( typeof( ViewPlan ) )
            .WherePasses( epf ); // only deal with ViewPlan

              // Use string evaluator and string rule to test string parameter
              // Filter all elements whose view name contains level

              String ruleValStr = "Level";

              testParam = BuiltInParameter.VIEW_NAME;

              pvp = new ParameterValueProvider(
            new ElementId( (int) testParam ) );

              FilterStringRuleEvaluator fnrvStr
            = new FilterStringContains();

              paramFr = new FilterStringRule(
            pvp, fnrvStr, ruleValStr, false );

              collector = new FilteredElementCollector( doc );

              collector.OfClass( typeof( ViewPlan ) )
            .WherePasses( epf ); // only deal with ViewPlan
        }
    /// <summary>
    /// Find a specific family type for a wall, which is a system family. 
    /// Most efficient way to find a named family symbol: use a parameter filter.
    /// </summary>
    public Element FindFamilyType_Wall_v3(
      string wallFamilyName,
      string wallTypeName)
    {
      ParameterValueProvider provider
        = new ParameterValueProvider(
          new ElementId(BuiltInParameter.DATUM_TEXT));

      FilterStringRuleEvaluator evaluator
        = new FilterStringEquals();

      FilterRule rule = new FilterStringRule(
        provider, evaluator, wallTypeName, true);

      ElementParameterFilter filter
        = new ElementParameterFilter(rule);

      return new FilteredElementCollector(_doc)
        .OfClass(typeof(WallType))
        .WherePasses(filter)
        .FirstElement();
    }
        /// <summary>
        /// Use a parameter filter to return the first element
        /// of the given type and with the specified string-valued
        /// built-in parameter matching the given name.
        /// </summary>
        Element GetFirstElementOfTypeWithBipString(
            Type type,
            BuiltInParameter bip,
            string name)
        {
            FilteredElementCollector a
            = GetElementsOfType( type );

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterStringRuleEvaluator evaluator
            = new FilterStringEquals();

              FilterRule rule = new FilterStringRule(
            provider, evaluator, name, true );

              ElementParameterFilter filter
            = new ElementParameterFilter( rule );

              return a.WherePasses( filter ).FirstElement();
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Application app = uiapp.Application;
              Document doc = uidoc.Document;

              Reference r = uidoc.Selection.PickObject(
            ObjectType.Element );

              // 'Autodesk.Revit.DB.Reference.Element' is
              // obsolete: Property will be removed. Use
              // Document.GetElement(Reference) instead.
              //Wall wall = r.Element as Wall; // 2011

              Wall wall = doc.GetElement( r ) as Wall; // 2012

              //Parameter parameter = wall.get_Parameter( "Unconnected Height" ); // 2014, causes warning CS0618: 'Autodesk.Revit.DB.Element.get_Parameter(string)' is obsolete: 'This property is obsolete in Revit 2015, as more than one parameter can have the same name on a given element. Use Element.Parameters to obtain a complete list of parameters on this Element, or Element.GetParameters(String) to get a list of all parameters by name, or Element.LookupParameter(String) to return the first available parameter with the given name.'
              Parameter parameter = wall.get_Parameter( BuiltInParameter.WALL_USER_HEIGHT_PARAM ); // 2015, avoids warning, in language indepependent and more effective to look up

              ParameterValueProvider pvp
            = new ParameterValueProvider( parameter.Id );

              FilterNumericRuleEvaluator fnrv
            = new FilterNumericGreater();

              FilterRule fRule
            = new FilterDoubleRule( pvp, fnrv, 20, 1E-6 );

              ElementParameterFilter filter
            = new ElementParameterFilter( fRule );

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              // Find walls with unconnected height
              // less than or equal to 20:

              ElementParameterFilter lessOrEqualFilter
            = new ElementParameterFilter( fRule, true );

              IList<Element> lessOrEqualFounds
            = collector.WherePasses( lessOrEqualFilter )
              .OfCategory( BuiltInCategory.OST_Walls )
              .OfClass( typeof( Wall ) )
              .ToElements();

              TaskDialog.Show( "Revit", "Walls found: "
            + lessOrEqualFounds.Count );

              return Result.Succeeded;
        }
        /// <summary>
        /// Return the viewport on the given
        /// sheet displaying the given view.
        /// </summary>
        Element GetViewport( ViewSheet sheet, View view )
        {
            Document doc = sheet.Document;

              // filter for view name:

              BuiltInParameter bip
            = BuiltInParameter.VIEW_NAME;

              ParameterValueProvider provider
            = new ParameterValueProvider(
              new ElementId( bip ) );

              FilterStringRuleEvaluator evaluator
            = new FilterStringEquals();

              FilterRule rule = new FilterStringRule(
            provider, evaluator, view.Name, true );

              ElementParameterFilter name_filter
            = new ElementParameterFilter( rule );

              BuiltInCategory bic
            = BuiltInCategory.OST_Viewports;

              // retrieve the specific named viewport:

              //Element viewport
              //  = new FilteredElementCollector( doc )
              //    .OfCategory( bic )
              //    .WherePasses( name_filter )
              //    .FirstElement();
              //return viewport;

              // unfortunately, there are not just one,
              // but two candidate elements. apparently,
              // we can distibuish them using the
              // owner view id property:

              List<Element> viewports
            = new List<Element>(
              new FilteredElementCollector( doc )
            .OfCategory( bic )
            .WherePasses( name_filter )
            .ToElements() );

              Debug.Assert( viewports[0].OwnerViewId.Equals( ElementId.InvalidElementId ),
            "expected the first viewport to have an invalid owner view id" );

              Debug.Assert( !viewports[1].OwnerViewId.Equals( ElementId.InvalidElementId ),
            "expected the second viewport to have a valid owner view id" );

              int i = 1;

              return viewports[i];
        }