Retrieve Basic wall by filterelementcollector without Curtain wall

amir.aroesti
Advocate
Advocate

Retrieve Basic wall by filterelementcollector without Curtain wall

amir.aroesti
Advocate
Advocate

hi,

 

what is the best way to collect all the basic wall without the curtain wall by Revit API C#.

didnt find if basic wall it a family symbol or not.

 

Thanks

Reply
Accepted solutions (3)
3,009 Views
8 Replies
Replies (8)

TripleM-Dev.net
Advisor
Advisor

Hi,

 

Unfortunately you can't get it direct from the instance, you will need to cast the elements to a [Wall] and then evaluate the property [Wall.WallType.Kind=Basic]

Or first get all CurtainWall Types and use the typeid as a inverted filter....depending you're addin processes.

 

Wall.WallType = Wall.WallType 

WallType .Kind = WallType.Kind 

 

Basic WalltypeBasic WalltypeCurtain WallTypeCurtain WallType

 

 

 

 

 

 

 

 

- Michel

0 Likes

amir.aroesti
Advocate
Advocate

thanks for quick respond @TripleM-Dev.net .

 

you talking about something like that?

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            IList<Element> walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic).ToList();

 

0 Likes

TripleM-Dev.net
Advisor
Advisor
Accepted solution
IList<Element> walls => should be IList<Wall> walls 

But it will raise a error if in-place walls are used.

 

I would use something like this, no need to worry about in-place walls

FilteredElementCollector BasicWallCollector = new FilteredElementCollector(doc).OfClass(typeof(Wall));
            IEnumerable<Wall> BasicWalls = BasicWallCollector.Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic);

 

If in-place walls should be taken into account, also use something like this:

FilteredElementCollector InplaceWallCollector = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Walls);

 

- Michel

0 Likes

amir.aroesti
Advocate
Advocate

thanks @TripleM-Dev.net ,

 

your solution works fine.

 

can you try to explain why mine doesnt work?

if replace <element> in <walls> as you said.

 

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            IList<Wall> walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic);

 

 

Thank you very much

0 Likes

TripleM-Dev.net
Advisor
Advisor

The line below won't work, list items can't be cast to another type (not even to it's base class) without iterating over its items.

IList<Wall> walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic);

 

Option 1:

IList<Wall> walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic).ToList();

 

Option 2 (keep IEnumerable)

IEnumerable<Element> walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic);

 

Option 3 use Var:

var walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic).ToList();

 

Or cast the items back to Element.

 

- Michel 

0 Likes

TripleM-Dev.net
Advisor
Advisor
FilteredElementCollector collector = new FilteredElementCollector(doc);
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            IList<Wall> walls = collector.WherePasses(filter).Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic).Tolist();

 

.ToList() missing at the end.

0 Likes

amir.aroesti
Advocate
Advocate
Accepted solution

thank you @TripleM-Dev.net 

 

the problem on my solution was retrieve  the wall category (ofCatgory) that include also the Wall Types in my document and then it`s not possible to cast wall type into a wall.

when you create the collector you use ofClass that retrieve only the instance.

is that make sense ?

 

             FilteredElementCollector collector = new FilteredElementCollector(doc);
             ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            IList<Wall> walls = collector.WherePasses(filter).WhereElementIsNotElementType().Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic).ToList();

in my original code there is no WhereElementIsNotElementType()

 

0 Likes

TripleM-Dev.net
Advisor
Advisor
Accepted solution
....

 

when you create the collector you use ofClass that retrieve only the instance.

is that make sense ?


Don't you only want the instances?, only the OfCategory would return Instance and Types that's correct.

 


@amir.aroesti wrote:

 

             FilteredElementCollector collector = new FilteredElementCollector(doc);
             ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            IList<Wall> walls = collector.WherePasses(filter).WhereElementIsNotElementType().Cast<Wall>().Where(w => w.WallType.Kind == WallKind.Basic).ToList();

 

in my original code there is no WhereElementIsNotElementType()

 


Be carefull with the code above, if you retrieve the elements by category also In-Place Model Walls will be retrieved and they are FamilyInstances, so the Cast to Wall will Fail, use the OfClass method to ignore them and then also no need for WhereElementIsNotElementType

 

Also ".WherePasses(filter). " can be replaced by the inline version: ".Ofcategory(<Bultincategory>)."

 

- Michel

 

 

0 Likes