Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is it Show Filter

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Arciviz
407 Views, 5 Replies

Is it Show Filter

I have use. 

Is it Show Filter

String Section_Name = "XXXXXXX";

IEnumerable<Element> elems = collect.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>()
 .Where(x => x.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString() == Section_Name);

 

Any alternate method using LINQ without BuiltInParameter?

 

Tags (1)
5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: Arciviz

Please check your spelling before posting!

 

I assume you mean to ask:

 

Question: Is this filter a slow filter?

 

Answer: No, it is not. It is even slower than a slow filter.

 

This example retrieves the element data from Revit to the .NET add-in memory space, and the uses .NET and LINQ to post-process it.

 

http://thebuildingcoder.typepad.com/blog/2015/12/quick-slow-and-linq-element-filtering.html

 

You could convert it to a fast filter by implementing a parameter filter to compare the family name:

 

https://thebuildingcoder.typepad.com/blog/2018/06/forge-tutorials-and-filtering-for-a-parameter-valu...

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6
jeremytammik
in reply to: Arciviz

I cleaned up The Building Coder sample code demonstrating retrieving named family symbols using either LINQ or a parameter filter for you:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

 

    #region Retrieve named family symbols using either LINQ or a parameter filter
    static FilteredElementCollector
      GetStructuralColumnSymbolCollector(
        Document doc )
    {
      return new FilteredElementCollector( doc )
        .OfCategory( BuiltInCategory.OST_StructuralColumns )
        .OfClass( typeof( FamilySymbol ) );
    }

    static IEnumerable<Element> Linq( 
      Document doc, 
      string familySymbolName )
    {
      return GetStructuralColumnSymbolCollector( doc )
        .Where( x => x.Name == familySymbolName );
    }

    static IEnumerable<Element> Linq2( 
      Document doc, 
      string familySymbolName )
    {
      return GetStructuralColumnSymbolCollector( doc )
        .Where( x => x.get_Parameter( 
          BuiltInParameter.SYMBOL_NAME_PARAM )
            .AsString() == familySymbolName );
    }

    private static IEnumerable<Element> FilterRule( 
      Document doc, 
      string familySymbolName )
    {
      return GetStructuralColumnSymbolCollector( doc )
        .WherePasses(
          new ElementParameterFilter(
            new FilterStringRule(
              new ParameterValueProvider(
                new ElementId( BuiltInParameter.SYMBOL_NAME_PARAM ) ),
              new FilterStringEquals(), familySymbolName, true ) ) );
    }

    private static IEnumerable<Element> Factory( 
      Document doc, 
      string familySymbolName )
    {
      return GetStructuralColumnSymbolCollector( doc )
        .WherePasses(
          new ElementParameterFilter(
            ParameterFilterRuleFactory.CreateEqualsRule(
              new ElementId( BuiltInParameter.SYMBOL_NAME_PARAM ),
              familySymbolName, true ) ) );
    }
    #endregion // Retrieve named family symbols using either LINQ or a parameter filter

 

I hope this clarifies.

  

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 6
Arciviz
in reply to: jeremytammik

Hi,

Please verify below code

//FilteredElementCollector collect = new FilteredElementCollector(doc);
        //IEnumerable<Element> elems = collect.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>()
        //  .Where(x => x.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString() == "Modular Gang Box");

        FilteredElementCollector collect = new FilteredElementCollector(doc,uidoc.ActiveView.Id);
        IEnumerable<Element> elems = collect.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>()
          .Where(x => x.Symbol.Family.Name.Equals("Modular Gang Box"));

I ask you sorry if I made mistake. 

Regards,

Sudhan.

 

Message 5 of 6
jeremytammik
in reply to: Arciviz

If this works for you and does what you need, then all is fine.

 

However, this is not a fast filter, nor is it a slow filter.

 

It is slower still.

 

The Where clause is a LINQ construct, in .NET, not a Revit filter at all.

 

In order for it to work, the Revit API has to transport all the element data out of the Revit memory space to .NET, where it is being post-processed.

 

This transport process is called marshalling and costs more time than all Revit filters, regardless whether they are fast or slow.

 

I cleaned up and published my previous answer on The Building Coder, in case that helps:

 

https://thebuildingcoder.typepad.com/blog/2019/04/slow-slower-still-and-faster-filtering.html

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 6
Arciviz
in reply to: jeremytammik

Thanks for the valuable blog. It is very much useful.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community