Painting walls using Dynamo

Hello again! As it turns out, moving all your livelihood to a different country is quite an absorbing process and I had to skip on my blogging for a bit. But now I’m back and…


…picture a massive hospital model in Revit that’s in dire need of painting. The default tool for applying paint is not the most efficient one to say the least and the deadline is approaching. What do you do? Since taking a holiday break was not an option, my second guess was to use Dynamo for that.

This script can be broken into two parts.

First part deals with sorting the walls per width and base constraint. To my surprise, the former wasn’t as straight forward I thought (It might have something to do with family structure for “Walls” category). In order to get the value of width, I used the following combination of two Python scripts:

import clr
from Autodesk.Revit.DB import *
items = UnwrapElement(IN[0])
typelist = list()
for item in items:
OUT = typelist


check = IN[0]
items = IN[1]
     if isinstance(check, (list)): OUT = items
else: OUT = items[0]

Combining those two with some basic BoolMasks leaves me with a list of walls-to-be-painted. Now to the second part – applying paint.

I must admit, my Revit API game isn’t the strongest, so to get this (simple, I know) script working I had to consult it with a colleague of mine. The final product is as follows:

import clr
from Autodesk.Revit.DB import *
import Revit
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument

elems = UnwrapElement(IN[0])
paintmat = UnwrapElement(IN[1])

for elem in elems:
     for geo in elem.get_Geometry(Options()):
             for face in geo.Faces:
                      doc.Paint(elem.Id, face, paintmat.Id)
OUT = elems

One interesting thing I’ve noticed is that the Python part of this Dynamo script seems to be “remembering” the values, i.e. when I’m done with painting one selections of walls and I want change the values by which I sort them – this script insists on painting the original selection. I think I’m missing something obvious here, feel free to enlighten me.