I wonder if it’s possible to override RGB of the material of a list of families, kind of like element.overrideInView but not view specific. what I’m trying to achieve is to generate colour/pattern studies of seatings in a 20,000 stadium. The testing part could be easily done in Grasshopper, what I’m unsure of feed back the data from grasshopper back to Dynamo/Revit. My initial thought is to generate a excel spreadsheet of RGB of all the seatings via Grasshopper and override the material with the RGB from the spreadsheet. but then I got stuck…
I also thought of creating say 100 dummies materials and to change the colour of those materials using a list of RGB from a spreadsheet. I’m hoping I could generate these material using dynamo instead of me doing it one by one manually. I tried the method in this post https://forum.dynamobim.com/t/create-new-material-thermal-physical-properties-using-dynamo-how/4365/11?u=lamsherman
but keep getting “Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
expected an indented block” with the python script
it would be great if anyone could give me a pointer as to where i went wrong…
Thanks
@lamsherman you need to indent your code inside the functions:
Could you also paste the code?
import clr
clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
def ToRevitColor(dynamoColor):
return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)
def ToDynamoObject(revitObject, isRevitOwned=False): # isRevitOwned should be False if Dynamo script created the object.
return revitObject.ToDSType(isRevitOwned)
doc = DocumentManager.Instance.CurrentDBDocument
names = IN[0]
transparencies = IN[1]
colors = IN[2]
newMaterials = []
for mat_name, transparency, color in zip(names, transparencies, colors):
TransactionManager.Instance.EnsureInTransaction(doc)
new_mat_id = Material.Create(doc, mat_name)
new_mat = doc.GetElement(new_mat_id)
new_mat.Color = ToRevitColor(color)
new_mat.Transparency = transparency
TransactionManager.Instance.TransactionTaskDone()
newMaterials.append(ToDynamoObject(new_mat))
OUT = newMaterials
I tried that and there’s still error
@lamsherman it works for me.
import clr
clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
def ToRevitColor(dynamoColor):
return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)
def ToDynamoObject(revitObject, isRevitOwned=False): # isRevitOwned should be False if Dynamo script created the object.
return revitObject.ToDSType(isRevitOwned)
doc = DocumentManager.Instance.CurrentDBDocument
names = IN[0]
transparencies = IN[1]
colors = IN[2]
newMaterials = []
for mat_name, transparency, color in zip(names, transparencies, colors):
TransactionManager.Instance.EnsureInTransaction(doc)
new_mat_id = Material.Create(doc, mat_name)
new_mat = doc.GetElement(new_mat_id)
new_mat.Color = ToRevitColor(color)
new_mat.Transparency = transparency
TransactionManager.Instance.TransactionTaskDone()
newMaterials.append(ToDynamoObject(new_mat))
OUT = newMaterials
2 Likes
I tried to paste the script
now it comes up with this error
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 29, in
Exception: The given value for name is already in use as a material element name.
Parameter name: name
I think I got it working now, for some reason it won’t works when Revit is in 3D view