'List[Element]' 对象没有属性 'Name'

'List[Element]' object has no attribute 'Name'

我有两个问题

  1. 级别列表不包含名称或其他参数,为什么我正在收集的每个元素都会出现此错误
  2. Urinals.Symbol.FamilyName("Type Comments").AsString() == "Urinal"): 不工作
from pyrevit.output import charts
from pyrevit import script
from pyrevit import revit, DB
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory
__context__ = 'zerodoc'

from System.Collections.Generic import List
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

from rpw import db, ui, doc
from pyrevit.framework import List
from pyrevit import revit, DB
room_filter = "WORK"


import rpw
from rpw import doc, uidoc, DB

# GET ALL ROOMS IN MODEL
rooms = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Rooms)
Urinals = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_PlumbingFixtures).WhereElementIsNotElementType().ToElements()
ub_count = 0
MRest_rooms = []
WRest_rooms = []
ADARest_rooms = []
Urinal_count = 0

#for u in Urinals:
#   if (Urinals.Symbol.FamilyName("Type Comments").AsString() == "Urinal"):
#    Urinal_count +=1
for r in rooms:
    if (r.Level.Name != 'CONTAINER LEVEL') and (r.LookupParameter("Name").AsString() == "M RESTROOM"):
        MRest_rooms.append(r)
    if (r.Level.Name != 'CONTAINER LEVEL') and (r.LookupParameter("Name").AsString() == "W RESTROOM"):
        WRest_rooms.append(r)

print "Number of Male Rest Room =",len(MRest_rooms)
print "Number of Female Rest Room =", len(WRest_rooms)

Level = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
print "Number of Level =",len(Level)
for i in Level:
 a = Level.Name
 print a

在调试器中看看它,你会亲眼看到。

你的错误是这一行:

Level = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
print "Number of Level =",len(Level)
for i in Level:
 a = Level.Name
 print a

应该是:

Level = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
print "Number of Level =",len(Level)
for i in Level:
 a = i.Name
 print a

for 循环中,您调用了 Level.Name,其中 Level 实际上是一个级别列表。因此例外。

注释掉的代码也有同样的问题:

for u in Urinals:
   if (Urinals.Symbol.FamilyName("Type Comments").AsString() == "Urinal"):
    Urinal_count +=1

替换为:

for u in Urinals:
   if (u.Symbol.FamilyName("Type Comments").AsString() == "Urinal"):
    Urinal_count +=1