简体   繁体   English

Revit Python宏与脚本

[英]revit python macros vs scripts

Why does the following code work as a script inRevitPython Shell but throw errors as a Macro when added to a Module? 为什么以下代码在RevitPython Shell中充当脚本,但是在添加到模块时却作为宏抛出错误? the idea is to collect the doors, query their host object for fire rating and frame details, then asign them to the doors. 想法是收集门,查询其宿主对象的防火等级和框架详细信息,然后将其分配给门。

The error is "None type has no attribute set()". 错误为“无类型没有属性set()”。 So it must be the door elements throwing this error. 因此,一定是门元素引发此错误。 But still, why does the very same code (only modifying how doc is defined) perform as a script but not a macro? 但是,为什么相同的代码(仅修改doc的定义方式)为什么作为脚本而不是宏执行?

def updateDoors(self):
    doc = self.Document
    doors = FilteredElementCollector(doc).OfCategory( BuiltInCategory.OST_Doors ).WhereElementIsNotElementType().ToElements()

    t = Transaction(doc, 'Door Update')
    t.Start()

    for d in doors:

        wallRating = "---"
        doorRating = "---"
        doorNumber = "---"
        wallFr = "---"
        wallH = "---"
        wallJ = "---"

        if d.Host is not None and d is not None:

            wallTypeId = d.Host.GetTypeId() 
            wall = doc.GetElement(wallTypeId)
            if wall.LookupParameter('Fire Rating') is not None:
                wallFr = wall.LookupParameter('Fire Rating').AsString()
            # Get Door Jamb from the wall
            if wall.LookupParameter('Frame Jamb') is not None:
                wallJ = wall.LookupParameter('Frame Jamb').AsString()
            # Get Door Head from the wall
            if wall.LookupParameter('Frame Head') is not None:
                wallH = wall.LookupParameter('Frame Head').AsString()

            if str(wallFr) == '':
                d.LookupParameter('Fire Rating-Instance').Set('--')
            if str(wallFr) == '0':
                d.LookupParameter('Fire Rating-Instance').Set('--')
            if str(wallFr) == '1':
                d.LookupParameter('Fire Rating-Instance').Set('45')
            if str(wallFr) == '2':
                d.LookupParameter('Fire Rating-Instance').Set('90')
            if str(wallFr) == '3':
                d.LookupParameter('Fire Rating-Instance').Set('120')

            if d.LookupParameter('Over ride wall assigned details').AsValueString() == 'No':    
                d.LookupParameter('Jamb').Set(wallJ)
                d.LookupParameter('Head').Set(wallH)

    t.Commit()

Run it in the SharpDevelop debugger and you will see for yourself which line of code causes the problem. 在SharpDevelop调试器中运行它,您将自己看到导致问题的代码行。 That will enable you to see the values of all the variables, and you can examine which of them is None. 这样一来,您就可以查看所有变量的值,并且可以检查其中哪个变量为None。

Furthermore, this line is very weird: 此外,这行很奇怪:

wall = doc.GetElement(wallTypeId)

It is assigning the wall type to the variable wall. 它将墙类型分配给可变墙。

All parameter values are being read from the wall type , not the wall instance. 所有参数值都是从wall 类型而不是wall实例读取的。

Is that your intention? 那是你的意图吗?

If so, I recommend renaming the wall variable to wallType to avoid confusing yourself and others. 如果是这样,我建议将wall变量重命名为wallType以避免混淆您自己和其他人。

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

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