Message 1 of 2
Revit 2022 python code to change all wall colors
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi so I'm trying to use python and Dynamo to change all the wall colors to a certain color. I've created the script but am getting an error and not sure why. I'm new to this so any help would be appreciated.
import clr
# import ProtoGeometry
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# import Revit Node
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# import Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
#Override graphics
def OverrideElement(element, color, fill, fillpatt):
ogs = OverrideGraphicSettings()
ogs.SetProjectionLinePatternId(fill.Id)
ogs.SetProjectionFillColor(color)
ogs.SetProjectionFillPatternId(fillpatt.Id)
doc.ActiveView.SetElementOverrides(element.Id, ogs)
#Convert the Dynamo color to Revit color.
def ConvertColor(element):
return Autodesk.Revit.DB.Color(element.Red, element.Green, element.Blue)
doc = DocumentManager.Instance.CurrentDBDocument
#Collect all the line patterns in the project.
patterns = FilteredElementCollector(doc).OfClass(LinePatternElement).ToElements()
fillPatSelected = list()
#search for line pattern
for i in range(len(patterns)):
namepick = patterns[i].ToDSType(True)
if namepick.Name == "Dash":
fillPatSelected.append(patterns[i])
elements = UnwrapElement(IN[0]) #Element to change
colors = ConvertColor(IN[1]) #Color.ByARGB node from Dynamo
fillPat = UnwrapElement(IN[2]) #Fill Pattern node from Dynamo
count = 0 #count to change color if elements are differnt color.
for i in elements:
TransactionManager.Instance.EnsureInTransaction(doc)
#Using def to override graphics.
OverrideElement(i, colors[count], fillPatSelected[0], fillPat)
count += 1
TransactionManager.Instance.TransactionTaskDone()
The error is,
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "<string>", line 50, in <module>
TypeError: iteration over non-sequence of type Wall