开发者

Revit families and filtering elements

开发者 https://www.devze.com 2023-03-16 07:14 出处:网络
I need to filter the selected elements by family. We have a timber beam family and I need to modify only sele开发者_运维技巧cted elements that are part of the timber family.I\'ve looked online but I

I need to filter the selected elements by family.

We have a timber beam family and I need to modify only sele开发者_运维技巧cted elements that are part of the timber family. I've looked online but I can't find anything that shows me how to do it. I'm new to revit.

//get all instaces if family objects
FilteredElementCollector familyInstanceCollector = 
  new FilteredElementCollector(doc);

familyInstanceCollector.OfClass(typeof(FamilyInstance))
  .WherePasses(new FamilySymbolFilter(new ElementId(140519)));

MessageBox.Show(familyInstanceCollector.Count<Element>().ToString());

foreach (Element element in familyInstanceCollector)
  MessageBox.Show(element.Name);


I'm not sure if creating a new ElementId like that will work, and I"m not sure if you can predict the ElementId across projects anyhow? Best way would be to do a filter to search for the family symbol you are looking for first, then use that result to find the instances.

Check out the .chm file that comes in the SDK, here's a sample from it:

// Creates a FamilyInstance filter for elements that are family instances of the given    family symbol in the document

// Find all family symbols whose name is "W10X49"
FilteredElementCollector collector = new FilteredElementCollector(document);
collector = collector.OfClass(typeof(FamilySymbol));

// Get Element Id for family symbol which will be used to find family instances
var query = from element in collector where element.Name == "W10X49" select element;
List<Element> famSyms = query.ToList<Element>();
ElementId symbolId = famSyms[0].Id;

// Create a FamilyInstance filter with the FamilySymbol Id
FamilyInstanceFilter filter = new FamilyInstanceFilter(document, symbolId);

// Apply the filter to the elements in the active document
collector = new FilteredElementCollector(document);
ICollection<Element> familyInstances = collector.WherePasses(filter).ToElements();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号