Element override material in view

Hi,
I am trying to create a script to easily change an element’s material such as Element.OverrideColorInView But with a material instead of a color.
Any suggestions? Best

To my knowledge you can’t override a material (with another material).

If you have to change an element’s material I would suggest using the paint-option.

I have here an example using a paint method with py. script by René Castillo Picazo.
The only problem with this is that when the element is painted it can’t be painted again without the paint being removed first.

A Removing paint script or a modification of script below would solve the issue.

# Copyright(c) René Castillo Picazo
# México 2017
# cadesigner.mex@gmail.com


import clr

clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

import Autodesk
import RevitServices

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc =  DocumentManager.Instance.CurrentDBDocument


surfaces = IN[0]
material = UnwrapElement(IN[1])

def PaintFace(surf, mat):
elemRef = surf.Tags.LookupTag("RevitFaceReference")
elem = doc.GetElement(elemRef)
face = elem.GetGeometryObjectFromReference(elemRef)

if not (doc.IsPainted(elem.Id, face)):
    return doc.Paint(elem.Id, face, mat.Id)
  

TransactionManager.Instance.EnsureInTransaction(doc)

if (isinstance(surfaces, list)):
[PaintFace(j, material) for i in surfaces for j in i]
else:
PaintFace(surfaces, material)              

TransactionManager.Instance.TransactionTaskDone()