Change Paint of some faces of wall

I want to change the paint of all the walls faces which have this(material in blue ) to material in red!


and I am having trouble in this

Connect from code block. I guess it requires a string input.

I have isolated the walls which have the first WF-01 paint on them but I can not understand how to take this code further…like now for the walls selected I need the faces which were painted with WF-01 and then re paint them with WF-02…and I need to be precise in this because I don’t want to change the paint on other faces of the walls
Currently I don’t want WF-01 on any of my walls in my project

You have to use that method
https://www.revitapidocs.com/2020.1/9268395e-a9cb-ff79-20ab-1ed261220513.htm

I am actually a new user of Dynamo and I don’t have much understanding of working on revit api or C#

Take a look at here:

I have seen these posts but I am not sure how to specifically select the faces I want to select

@sensiblehira continuing from the post of @Deniz_Maral and originally solved by @MartinSpence, I guess this can help you, the script will scan the faces for the old material and paint them with the new material.

import clr

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

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

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

elems = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
oldMat = UnwrapElement(IN[0])
newMat = UnwrapElement(IN[1])

gOpts = Options()

TransactionManager.Instance.EnsureInTransaction(doc)
for i in elems:
	geom = i.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(i.Id, f, newMat.Id)
			else:
				pass
TransactionManager.Instance.TransactionTaskDone()
		
OUT = 0
1 Like

it is giving this error
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 27, in
AttributeError: ‘GeometryInstance’ object has no attribute ‘Faces’

it actually worked on some but some were left …I wonder why

@sensiblehira can you share a sample revit file?

// Paint any unpainted faces of a given wall
public void PaintWallFaces(Wall wall, ElementId matId)
{
    Document doc = wall.Document;
    GeometryElement geometryElement = wall.get_Geometry(new Options());
    foreach (GeometryObject geometryObject in geometryElement)
    {
        if (geometryObject is Solid)
        {
            Solid solid = geometryObject as Solid;
            foreach (Face face in solid.Faces)
            {
                if (doc.IsPainted(wall.Id, face) == false)
                {
                    doc.Paint(wall.Id, face, matId);
                }
            }
        }
    }
}

I think you should check that GeometryInstances are solid or with try-except pass the elements.

import clr

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

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

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

elems = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
oldMat = UnwrapElement(IN[0])
newMat = UnwrapElement(IN[1])

gOpts = Options()
output=[]
TransactionManager.Instance.EnsureInTransaction(doc)
for i in elems:
	geom = i.get_Geometry(gOpts)
	for j in geom:
		for k in j.Faces:
			
			if k.MaterialElementId ==oldMat.Id:
				doc.Paint(i.Id, k, newMat.Id)
				output.append("Success")
			else:
				pass
TransactionManager.Instance.TransactionTaskDone()
		
OUT = output
1 Like

I used this code instead and it did not return the error:

import clr

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

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

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

elems = FilteredElementCollector(doc).OfClass(Wall).ToElements()
oldMat = UnwrapElement(IN[0])
newMat = UnwrapElement(IN[1])

gOpts = Options()

TransactionManager.Instance.EnsureInTransaction(doc)
for i in elems:
	geom = i.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(i.Id, f, newMat.Id)
			else:
				pass
TransactionManager.Instance.TransactionTaskDone()
		
OUT = 0

Thanks for helping me out @Deniz_Maral @tradelie

1 Like