Revit族和过滤元素

发布于 2024-11-17 19:59:26 字数 529 浏览 3 评论 0原文

我需要按系列过滤选定的元素。

我们有一个木梁系列,我只需要修改属于木梁系列的选定元素。

//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 need to filter the selected elements by family.

We have a timber beam family and I need to modify only selected elements that are part of the timber family.

//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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮光之海 2024-11-24 19:59:26

我不确定创建这样的新 ElementId 是否有效,并且我不确定您是否可以预测跨项目的 ElementId?最好的方法是先进行过滤器来搜索您要查找的系列符号,然后使用该结果查找实例。

查看 SDK 中的 .chm 文件,以下是其中的示例:

// 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();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文