1

我正在进入 revit python wrapper / revit python shell 并且在一个非常简单的任务上遇到了麻烦。

我的项目中有一面墙,我只是想将顶部偏移从 0'-0" 更改为 4'-0"。我已经能够更改属性中的注释,但仅此而已。

这是我的代码:

import rpw
from rpw import revit, db, ui, DB, UI

element = db.Element.from_int(352690)
with db.Transaction('Change height'):
    element.parameters['Top Offset'].value = 10 

这是我的错误:

[ERROR] Error in Transaction Context: has rolled back.
Exception : System.Exception: Parameter is Read Only: Top Offset
   at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.ExecuteAndWrap(ScriptScope scope, ObjectHandle& exception)

任何和所有的帮助表示赞赏。我已经阅读了文档,但是他们似乎没有阅读只读项目。

我在 revit 2019。RPS 正在使用 python 2.7.7

4

1 回答 1

1

我认为这是一个“Revit Python Wrapper”(RPW)问题,而不是“RevitPythonShell”(RPS)问题,我熟悉 RPS 中处理事务的方式,但 RPW 的文档似乎完全不同。

这是您的代码在 RevitPythonShell 中的样子:

import clr
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
from Autodesk.Revit.UI import *
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
ui = __revit__.ActiveUIDocument

element = doc.GetElement(ElementId(352690))

t = Transaction (doc, 'Change Height')
t.Start()
parameter = element.GetParameters('Top Offset')[0]
parameter.Set(10)   
t.Commit()
于 2019-06-23T20:20:35.223 回答