简体   繁体   中英

Revit Python Wrapper

i'm getting into revit python wrapper / revit python shell and am having trouble on a very simple task.

I have one wall in my project and I'm just trying to change the top offset from 0'- 0" to 4'-0". I've been able to change the Comments in the properties but that's about it.

Here's my code:

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 

Here's my error:

[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)

Any and all help is appreciated. I've read the docs however they dont seem to go over Read Only items.

I'm in revit 2019. RPS is using python 2.7.7

I think this is a "Revit Python Wrapper" (RPW) question more than a "RevitPythonShell" (RPS) one, Im familiar with the way transactions are handled in RPS but the documentation for RPW seems quite different.

This is what your code would look like in 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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