Hi,
I need help with this. I am trying to create a lot of materials in Revit. I just need the name of the material and the color. I have started with a simple case without considering Excel, but it doesn’t work because it only creates the last material of the list. I attach the dynamo file
Following is presented the Python Script used in this case.
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):return revitObject.ToDSType(isRevitOwned)
doc = DocumentManager.Instance.CurrentDBDocument
names = IN[0]
colors = IN[1]
newMaterials =
for mat_name, color in zip(names, 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)
TransactionManager.Instance.TransactionTaskDone()
newMaterials.append(ToDynamoObject(new_mat))
#Asigne la salida a la variable OUT.
OUT = newMaterials
Thank you very much