I am trying to duplicate the wall of 6 feet and create a new wall of 10 feet but i am getting this error in revit2020, please see the code and error:
Error:- Autodesk.Revit.Exceptions.InvalidOperationException: The parameter is read-only.
Code:-
import Autodesk
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInParameter, BuiltInCategory, Line, Wall, XYZ, Transaction
doc = __revit__.ActiveUIDocument.Document
# Prompt user for wall height with input validation
while True:
wall_height_input = input("Enter the height of the wall in feet: ")
try:
wall_height = float(wall_height_input)
break
except ValueError:
print("Invalid input. Please enter a valid numeric value.")
levels = FilteredElementCollector(doc).OfCategory(
BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToElements()
# Find the wall type with 6 feet thickness
wall_type_6_feet = None
for wall in walls:
name = wall.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
if name == '6 feet':
wall_type_6_feet = wall
break
if wall_type_6_feet is None:
print("Wall type with 6 feet thickness not found. Aborting.")
else:
# Find the level with elevation 1'
level_1 = None
for level in levels:
elevation = level.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble()
if elevation == 304.8 / 304.8:
level_1 = level
break
if level_1 is None:
print("Level with elevation 1' not found. Aborting.")
else:
p_1 = XYZ(0, 0, level_1.Elevation)
p_2 = XYZ(50, 0, level_1.Elevation)
line_1 = Line.CreateBound(p_1, p_2)
lines = [line_1]
t = Transaction(doc, 'Create Wall')
t.Start()
# Duplicate the wall type and change its thickness to 10 feet within the transaction
wall_type_10_feet = wall_type_6_feet.Duplicate("10 feet")
wall_type_10_feet.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).Set(
10.0 / 304.8) # Convert 10 feet to Revit's unit (304.8)
for line in lines:
# Create the wall with the specified height and 10 feet thickness
wall_1 = Wall.Create(doc, line, wall_type_10_feet.Id, level_1.Id, wall_height / 304.8, 0, False, True)
t.Commit()
IronPython Traceback:
Traceback (most recent call last):
File “D:\MyExtensions\Rvtcad.extension\Rvtcad.tab\Line.panel\ttest.pushbutton\ttest_script.py”, line 51, in
Exception: The parameter is read-only.
Script Executor Traceback:
Autodesk.Revit.Exceptions.InvalidOperationException: The parameter is read-only.
at Autodesk.Revit.DB.Parameter.Set(Double value)
at Microsoft.Scripting.Interpreter.FuncCallInstruction3.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.DynamicInstruction4.Run(InterpretedFrame frame)
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 PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)
Hey, to add to the discussion, this week I have been messing with Walls so maybe I can try to help out. Like @Jean-Marc said, you cant change that parameter, the opposite with the Commentary parameter for example.
Eric Frits did some cool stuff to change material type, explained here. Here is his source code. Finally, about width change here. a sample of what i did to change the width, from what i understand, it is necessary change the core structure width.
Wallbase = doc.GetElement(ElementId(1740)) # Generic Family 200mm
newwalltype = Wallbase.Duplicate("PM 1.00")
newwalltypeID = newwalltype.Id.ToString()
cs = newwalltype.GetCompoundStructure()
i = cs.GetFirstCoreLayerIndex()
cs.SetLayerWidth(i, 1000/304.8)
cs.SetMaterialId(i, ElementId(1250)) # Define specific Material as Armed concrete
newwalltype.SetCompoundStructure(cs)
Of course, a lot can be refined, much hard coded etc, me myself am not sure i understand it completely but i hope it helps out !
Any corrections feel free community, I am always wanting to learn something new
Hi @Jean-Marc Thank you very much. I really appreciate your knowledge and valuable time. :). It is working very well. i am happy to be part of your community
@Jean-Marc I found, this code is only creating a 10 feet wall name, but inside the thickness of the 10 feet wall is 6’. it seems like this is duplicating the name not changing the thickness.
import Autodesk
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInParameter, BuiltInCategory, Line, Wall, XYZ, Transaction
doc = __revit__.ActiveUIDocument.Document
# Prompt user for wall height with input validation
while True:
wall_height_input = input("Enter the height of the wall in feet: ")
try:
wall_height = float(wall_height_input)
break
except ValueError:
print("Invalid input. Please enter a valid numeric value.")
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToElements()
# Find the wall type with 6 feet thickness
wall_type_6_feet = None
for wall in walls:
name = wall.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
if name == '6 feet':
wall_type_6_feet = wall
break
if wall_type_6_feet is None:
print("Wall type with 6 feet thickness not found. Aborting.")
else:
# Find the level with elevation 1'
level_1 = None
for level in levels:
elevation = level.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble()
if elevation == 304.8 / 304.8:
level_1 = level
break
if level_1 is None:
print("Level with elevation 1' not found. Aborting.")
else:
p_1 = XYZ(0, 0, level_1.Elevation)
p_2 = XYZ(50, 0, level_1.Elevation)
line_1 = Line.CreateBound(p_1, p_2)
lines = [line_1]
t = Transaction(doc, 'Create Wall')
t.Start()
# Duplicate the wall type and modify the thickness of a specific layer
wall_type_10_feet = wall_type_6_feet.Duplicate("10 feet")
compound_structure = wall_type_10_feet.GetCompoundStructure()
layer_index = 0 # Index of the layer to modify (0 being the outermost layer)
new_thickness = 10.0 / 304.8 # New thickness in Revit's unit (304.8)
# Change the thickness of the selected layer
compound_structure.SetLayerWidth(layer_index, new_thickness)
for line in lines:
# Create the wall with the specified height and modified thickness
wall_1 = Wall.Create(doc, line, wall_type_10_feet.Id, level_1.Id, wall_height / 304.8, 0, False, True)
t.Commit()