Filtering Walls by Name and Base Constraint

Filtering Walls by Name and Base Constraint

Anonymous
Not applicable
2,321 Views
4 Replies
Message 1 of 5

Filtering Walls by Name and Base Constraint

Anonymous
Not applicable

I'm having difficulty trying to filter out my walls by a specific name (which works) and by the walls' base constraint to equal the associated level of my active view. This is the code I currently have. The Build is successful but doesn't do anything when I execute the macro. I believe the issue is within the reading the string. Thank you in advance for the help.

 

 

Document doc = this.Application.ActiveUIDocument.Document;
            View myActiveView = doc.ActiveView;
            Parameter level = myActiveView.LookupParameter("Associated Level");
            String levelName = level.AsString();

FilteredElementCollector swwallfilter = new FilteredElementCollector(doc, myActiveView.Id);
                List<Element>swwalls = swwallfilter.OfCategory(BuiltInCategory.OST_Walls).ToList();
                
                    var swtypeelements = from element in swwallfilter
                    where element.Name.Contains("Shear Wall") &&
                        element.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Equals(levelName)
                        
                        select element;

 

0 Likes
Accepted solutions (1)
2,322 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I guess this doesn't go by name (string) but rather the level you are looking for.

 

BuiltInParameter.WALL_BASE_CONSTRAINT

 

should work by Id.

 

Please correct me if I am wrong, didn't try.

 

Christian 

0 Likes
Message 3 of 5

FAIR59
Advisor
Advisor
Accepted solution

element.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT) is a Parameter

 

so try

 

element.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).asValueString().Equals(levelName);

Message 4 of 5

Anonymous
Not applicable

Thank you! That worked. I knew it was something with the string. 

0 Likes
Message 5 of 5

r_b_1366
Explorer
Explorer
 

List<Wall> wallCollector = new List<Wall>();

string level= form1.Mylevel;

ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
FilteredElementCollector collector = new FilteredElementCollector(doc);

IList<Element> walls = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
foreach (Element e in walls)
{
string basconstraint = e.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsValueString();
if (basconstraint == level)
{
wallCollector.Add(e as Wall);
}

}

I think this is also useful for the Filtering Walls by Base Constraint



0 Likes