I am trying to Paint 120 materials to 120 floors. Using Dynamo /Python

I have automated the Paint material creation process but now to apply the Paint i can get it to do it for a single floor. But i want Dynamo and python to loop for multiple elements and materials in list form?
Here is the Python script i got after searching so much on the forums. This script is working fine for one element. how do i make it work for multiple materials and multiple floors.
Revit_EWEXZxWNKm
import clr

Here is the python script one is using

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

#Import Document and transcation manager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#referecing active document
doc = DocumentManager.Instance.CurrentDBDocument

elems = FilteredElementCollector(doc, doc.ActiveView.Id).ToElementIds()
elems = UnwrapElement(IN[0])
newMat = UnwrapElement(IN[1])


gOpts = Options()

TransactionManager.Instance.EnsureInTransaction(doc)
geom = elems.get_Geometry(gOpts)
for j in geom:
	face = j.Faces
	for f in face:
			#if doc.IsPainted(i.Id, f):
			#if f.MaterialElementId == oldMat.Id:
		doc.Paint(elems.Id, f, newMat.Id)
TransactionManager.Instance.TransactionTaskDone()

OUT = elems

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

#Import Document and transcation manager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#referecing active document
doc = DocumentManager.Instance.CurrentDBDocument
es=IN[0]
mats=IN[1]
painted=[]
for elems1,newmats1 in zip(es,mats):
	elems = FilteredElementCollector(doc, doc.ActiveView.Id).ToElementIds()
	elems = UnwrapElement(elems1)
	newMat = UnwrapElement(newmats1)
	
	
	gOpts = Options()
	
	TransactionManager.Instance.EnsureInTransaction(doc)
	geom = elems.get_Geometry(gOpts)
	for j in geom:
		face = j.Faces
		for f in face:
				#if doc.IsPainted(i.Id, f):
				#if f.MaterialElementId == oldMat.Id:
			doc.Paint(elems.Id, f, newMat.Id)
	TransactionManager.Instance.TransactionTaskDone()
	painted.append(elems)
OUT = painted
3 Likes


Great @Hyunu_Kim Thank you so much this. Awesome

1 Like