简体   繁体   English

如何在 Revit API 中获取系统族的族名?

[英]How to get family name of System family in Revit API?

I want to get a family name of "System family instance" such as wall, roof etc.我想获得“系统系列实例”的系列名称,例如墙壁、屋顶等。

I know that how to get a family name of Family instance, but I cannot figure out if the element is "System Family instance".我知道如何获取 Family 实例的姓氏,但我无法确定该元素是否为“System Family 实例”。

Thanks.谢谢。

(*Element e is the element that I picked.) (*元素 e 是我选择的元素。)

FamilyInstance finstance = e as FamilyInstance;
FamilySymbol ftype = finstance.Symbol;
string famname = ftype.FamilyName;

Please recommend the solution that is using the revit api.请推荐使用revit api的解决方案。

Look at What's New in the Revit 2015 API and search for ElementType API additions :查看Revit 2015 API 中的新增功能并搜索ElementType API 添加

The new property ElementType.FamilyName contains the localised string describing the family in which this ElementType belongs.新属性ElementType.FamilyName包含描述此 ElementType 所属系列的本地化字符串。 For family symbols, this will be the name of the associated Family.对于系列符号,这将是关联系列的名称。 For system family types, this will be the name used to group related types, such as "Oval Duct" or "Curtain Wall".对于系统族类型,这将是用于对相关类型进行分组的名称,例如“椭圆风管”或“幕墙”。

As @pooh mentioned in the comment, given an element you will need to call Element.GetTypeId() .正如@pooh 在评论中提到的,给定一个元素,您需要调用Element.GetTypeId() Here is a slightly more readable and robust answer:这是一个更具可读性和稳健性的答案:

   public static string GetFamilyName(Element e)
   {
      var eId = e?.GetTypeId();
      if (eId == null)
        return "";
      var elementType = e.Document.GetElement(eId) as ElementType;
      return elementType?.FamilyName ?? "";
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM