不可否认的价值

2024-09-30 18:33:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我在这里学习。。。你知道吗

我对“无”的价值感到困惑。在下面的代码段中,我试图找到视图参数“view Owner”要么为None,要么为!=无。你知道吗

下面的代码片段告诉我,我有一个3548个项目的视图列表长度和项目的数量!=无为316。如果我改变!=到==,结果为0。我不明白怎么会这样。。。thins不是没有就是没有?我想两次跑步的总和应该是-3548。你知道吗

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, View

    uidoc = __revit__.ActiveUIDocument
    doc = __revit__.ActiveUIDocument.Document


        selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]

        views = []

        if len(selection) == 0:
            cl_views = FilteredElementCollector(doc)
            views = cl_views.OfCategory( BuiltInCategory.OST_Views ).WhereElementIsNotElementType().ToElements()
        else:
            for sel in selection:
                if isinstance(sel, View):
                    views.append(sel)

        count = 0
        for v in views:
            if v.LookupParameter("View Owner")!=None:
                snumber = v.LookupParameter("View Owner").AsString()
                if snumber != None:
                    count= count+1
                    vowner = v.LookupParameter('View Owner').AsString()
                    if v.LookupParameter('View Name')!=None:
                        vname = v.LookupParameter('View Name').AsString()
                        vowner = vowner+vname
                    print(vowner)

        print len(views)
        print count

Tags: innoneviewfordocifcountviews
2条回答

在示例代码片段IMHO中,应该避免以下几点:

  • 如果可能的话,应始终避免按名称进行比较。它依赖于语言,比比较数字效率低。在这种情况下,很可能用元素id替换字符串比较。

  • 使用LookupParameter要比使用固定的内置参数枚举值来检索您感兴趣的参数效率低得多。

用途:

is None

以及

is not None

而是==!=

相关问题 更多 >