Paint All Faces of Selected Elements

1️⃣ Select Material

First of all I get all materials with FilteredElementCollector class and then I create a UI form using pyrevit.forms.SelectFromList function. You can get more information about it in pyRevit's Dev Doc - Effetive Inputs

2️⃣ Pick Elements

Then I use Selection.PickObjects method to allow user to select multiple elements, that should be painted. I also used pyrevit.forms.WarningBar to create an orange bar on the top, so it's more clear for the user what to do.

3️⃣ Paint Faces

Lastly, I painted all the faces. I had to get Geometry and iterate through its faces. And one I got the faces I used doc.Paint method to paint them.


# -*- coding: utf-8 -*-

#⬇️ IMPORTS
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
#pyRevit
from pyrevit import forms

#📦 VARIABLES
uidoc = __revit__.ActiveUIDocument
doc   = __revit__.ActiveUIDocument.Document #type: Document
    
#🎯 MAIN

#1️⃣ Select Material
all_materials = FilteredElementCollector(doc).OfClass(Material).ToElements()
sel_material  = forms.SelectFromList.show(all_materials,
                                multiselect=False,
                                name_attr='Name',
                                button_name='Select Material')
if not sel_material:
    forms.alert("Material wasn't Selected. Please Try Again.", exitscript=True)

#2️⃣ Pick Elements
with forms.WarningBar(title='Pick Elements:'):
    try:
        ref_picked_objects = uidoc.Selection.PickObjects(ObjectType.Element)
        selected_elements     = [doc.GetElement(ref) for ref in ref_picked_objects]
        if not selected_elements:
            forms.alert("Elements weren't selected. Please Try Again.",exitscript=True)
    except:
        forms.alert("Elements weren't selected. Please try again.", exitscript=True)


# 3️⃣ Paint Selected Elements
#🧬 FUNCTION: PAINT FACES
def paint_el_faces(el, mat_id):
    try:
        geometry_element = el.get_Geometry(Options())
        
        for geometry_object in geometry_element:
            if isinstance(geometry_object, Solid):
                solid = geometry_object
                for face in solid.Faces:
                    doc.Paint(el.Id, face, mat_id)
    except: pass

t = Transaction(doc, 'Paint Elements')
t.Start()  #🔓
for el in selected_elements:
    paint_el_faces(el, sel_material.Id)
t.Commit() #🔒

⌨️ Happy Coding!
Erik Frits