简体   繁体   中英

Revit Python have problem with isinstance()

I use if isinstance(ins,list): to check . but it returned false Although ins is the List[Object]

def getname(ins):
    name=[]
    if isinstance(ins,list):
        for i in ins:
            name.append(i.Name)
    else:
        name.append(ins.Name)
    return name

Levels = FilteredElementCollector(doc).OfClass(Level).ToElements()
ULevels = UnwrapElement(Levels)
Levelsname = getname(ULevels)

Error message is:

AttributeError: 'List[object]' object has no attribute 'Name'

You can do it in a single line of code like this:

[UnwrapElement(x).Name for x in FilteredElementCollector(doc).OfClass(Level).ToElements()]

Since I can see you are using Dynamo you can also do it like this:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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