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: 

Filtering Walls by Name and Base Constraint

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
desantis15
1739 Views, 4 Replies

Filtering Walls by Name and Base Constraint

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;

 

4 REPLIES 4
Message 2 of 5
chhadidg73
in reply to: desantis15

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 

Message 3 of 5
FAIR59
in reply to: desantis15

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
desantis15
in reply to: FAIR59

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

Message 5 of 5
r_b_1366
in reply to: desantis15

 

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



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