Set Render Color from Material

Is possible to set the Render Color from a Material in Revit? I’ve managed to mark the checkbox that says UseRenderAppearanceForShading while creating a New Material, but then the RGB is the Generic one (80,80,80). I’ll like to know if is possible to modify the Render Color has you can modify the other rest: SurfacePatternColor, CutPatternColor, Color.

I paste the code i’m working in, just missing setting the Render Color.

On the other hand, also would be nice to fill, all the rest of parameters, Manufactures, Description… if you know the ways that would be really useful.

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

def ToRevitColor(dynamoColor):
	return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)

def ToDynamoObject(revitObject, isRevitOwned=False): # isRevitOwned should be False if Dynamo script created the object.
	return revitObject.ToDSType(isRevitOwned)

doc = DocumentManager.Instance.CurrentDBDocument

mat_name = IN[0]
transparencies = IN[1]
colors = IN[2]
colors_surface = IN[3]
colors_cutpattern = IN[4]
use_render_app = IN[5]

newMaterials = []

for mat_name, transparency, color, color_surface,color_cutpattern, uses_render_app in zip(mat_name, transparencies, colors, colors_surface,colors_cutpattern,use_render_app):
	TransactionManager.Instance.EnsureInTransaction(doc)
	new_mat_id = Material.Create(doc, mat_name)
	new_mat = doc.GetElement(new_mat_id)
	new_mat.Transparency = transparency
	new_mat.SurfacePatternColor = ToRevitColor(color_surface)
	new_mat.CutPatternColor= ToRevitColor(color_cutpattern)
	new_mat.Color = ToRevitColor(color)	
	new_mat.UseRenderAppearanceForShading = uses_render_app
	TransactionManager.Instance.TransactionTaskDone()
	newMaterials.append(ToDynamoObject(new_mat))

OUT = "Oh Yeah Baby!!!"

Thanks in advance for any idea.

:v:

The color from Use Render Appearance For Shading is only grey until you give the material a render appearance asset with color information that doesn’t average out to gray.

Hi @Greg_McDowell,

In Revit you can edit manually that color render appearance without selection any render appearance asset. I though maybe you could do the same as the other colors from Dynamo.

Just in case i misunderstood your words. You mean that i should first assign an Render appearance asset and then i could change that color, all in Dynamo.

About the other parameters affecting the Material, manufactures, description… any idea how i could reach them?

Thanks for your time.

@Raul.Galdran did you manage to change any of the Appearance Assets’ properties? I am afraid that currently the API does not support this.
You can create or duplicate a new appearance asset and assign it (or an existing one) to a material, but I could not modify its properties:

gen=AppearanceAssetElement.GetAppearanceAssetElementByName(doc,"Generic")
app=AppearanceAssetElement.Duplicate(gen,mat_name)
new_mat.AppearanceAssetId=app.Id

Even in the RevitAPIdocs there is no trace of something interesting:
the AppearanceAssetElement class has a GetRenderingAsset and a SetRenderingAsset method which require an Asset as input.
None of these however show some pretty properties like Color…

1 Like

@GregX

I didnt manage to make any change about the rendering material or textures.

Thanks for the advise about duplicating the appearance from the material, i didnt know about this walkaroud.

Thanks again for your time.

For anyone interested:

Hello GregX,

how did you get to make the Duplicate method work? I copied your 3 rows of code, and Dynamo says:
AttributeError: ‘type’ object has no attribute 'Duplicate’
Do I need to import some functions from the API? Can you share the whole code?

Thanks in advance!

Can you paste what you did as Preformatted text to illustrate your request?

Hello Yna_Db,
my code goes like this:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.

matInput = IN[0]
matToCopy = IN[1]

import clr
clr.AddReference("RevitAPI")
clr.AddReference("System.Core")
import System
clr.ImportExtensions(System.Linq)
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

assetArray = []

for i in range(len(matInput)):
  	gen=AppearanceAssetElement.GetAppearanceAssetElementByName(doc,"Aluminum")
	app = AppearanceAssetElement.Duplicate(gen, matToCopy)
	matInput[i].AppearanceAssetId=app.Id
	assetArray.append(app)

OUT = assetArray

It’s too late for me and someone else will surely help, but you could be interested to first take a look at one of the links mentioned in this post:

Thank you!

Still issue in Revit 2022, Dynamo 2.12.

It took two people the whole evening to figure out what the number is…
It is two conversions between RGB to hex and then to decimal. But the trick is, you have to convert each color separately and then compose the hex number by switching R and B, because they are switched for some reason. So you are not converting RGB, but BGR…

For example: original RGB(0,150,255), you need switch R and B like this (255,150,0) and conver to to HEX FF9600. Then convert to decimal the whole number normally FF960016750080
Hex to decimal (Clockwork package work nice)