Here's the documentation for the relevant API material
我尝试做的是能够从Dynamo调用postable命令(在这种情况下,我甚至无法调试,因为 Autodesk.Revit.UI 的import子句失败了)。我从日志文件中得到了数字 10:05:57.614 ,但如果我无法导入正确的命名空间,对我来说意义不大。如果我不导入,那么Evaluator会告诉我,我想要进行的函数调用是未定义的。请帮忙。
这是否与Revit会话的状态有关,因为它执行Dynamo脚本?
以及相关的错误消息:
用于复制+粘贴..
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# 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")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System
dataEnteringNode = IN
elemType = UnwrapElement(IN[0])
cmdID = System.Enum.Parse(RevitCommandId, "10:05:57.614")
TransactionManager.Instance.EnsureInTransaction(doc)
uiapp.PostCommand("10:05:57.614")
OUT = uSelect
doc.Regenerate()
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
答案 0 :(得分:1)
这应解决无法导入RevitAPIUI.dll的问题:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
# 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
clr.ClearProfilerData()
uiPath = r'C:\Program Files\Autodesk\Revit 2016\RevitAPIUI.dll'
clr.AddReferenceToFileAndPath(uiPath)
from Autodesk.Revit.UI import *
def pickSomething():
from Autodesk.Revit.UI.Selection import ObjectType
picked = uiapp.ActiveUIDocument.Selection.PickObject(ObjectType.Element)
return picked
#Assign your output to the OUT variable.
OUT = pickSomething()