托管对象无效 - Dynamo 崩溃

The managed object is not valid - Dynamo Crashes

Dynamo 中的以下错误困扰了我好几个小时。

Warning:

IronPythonEvaluator.EvaluateIronPythonScript operation failed.

Traceback (most recent call last):

File " < string > ", line 33, in < module>

Exception: The managed object is not valid.

我不确定为什么会出现错误,如果有人与我分享其解决方案,我将不胜感激。谢谢

import clr

clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry

# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit

clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

import System
from System import Array
from System.Collections.Generic import *

import sys

pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

以上是我在使用 Dynamo/Revit API 时的标准导入。它已经为我工作了一段时间。

老实说,我希望 "actual" 能回答您的脚本无法运行的原因。唯一与我不同的是你引用某些东西的顺序。这应该不会影响它们的有效性。虽然它是发电机,但它非常反复无常。