Create Materials with Appearance color value using GeniusLoci package

Hi all,

I am trying to map colors as real materials in Revit so that I could render them.
I have successfully created the materials as shown below with the Graphics color created but the Appearance asset color value doesn’t change. I tried a node from GeniusLoci package but it just gives me null values. I still have no knowledge of Python and can’t really understand the code inside the node T_T. I hope somebody can assist. Thank you so much!!

Created Materials with Graphics color but no color in Appearance asset tab

Null values using Material Set Render Appearance color which is supposed to copy the Graphics color values to the Appearance Asset color:

Material Set Render Appearance color python code:

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
doc = DocumentManager.Instance.CurrentDBDocument

def tolist(obj):
    if hasattr(obj, '__iter__'): return obj
    else: return [obj]

materials = tolist(UnwrapElement(IN[0]))

for mat in materials :
	appearanceAssetId = mat.AppearanceAssetId
	assetElem = doc.GetElement(appearanceAssetId)
	TransactionManager.Instance.EnsureInTransaction(doc)
	with Visual.AppearanceAssetEditScope(assetElem.Document) as editScope:
		editableAsset = editScope.Start(assetElem.Id)
		genericDiffuseProperty = editableAsset.FindByName("generic_diffuse")
		genericDiffuseProperty.SetValueAsColor(mat.Color)
		editScope.Commit(True)
	TransactionManager.Instance.TransactionTaskDone()

OUT = materials

Hello.

Can you try taking the Python code out of the custom node and put it into a python node and see if any errors show up?

1 Like

Hi @archjahzzy,

You must add an appearance asset for each material before you change the color of the appearance asset or add a texture or a tint color.
Use the Material Create and Add AppearanceAssetElement node.

2 Likes

Hi @Alban_de_Chasteigner, thank you!

I am not sure why mine doesn’t work… do you have any idea? I sampled 4 items from the list because I have over a thousand materials:

Can you try flattening the inputs and removing the list levels?

and here’s the flattened version:
image

here’s a more complete graph:
image

1 Like

Do you have a material called “Default” ?
Are you working with Revit 2018.1 or later ?

If so, can you drop a sample file please ?

I am using 2018.3, and yes there is a material called “Default”… but the materials I’m creating have different names. I will send you the file.

1 Like

Well, it works on my side on your purged file.

3 Likes

Hmm…
Strange. Maybe it was just a bug? Anyways, thank you so much! I’ll try it again tomorrow. Hopefully it will work.

Hi all,

I guess the problem is in the computing power of my pc or it’s just buggy. It works when I split the material creation by batches of around 200 materials. :slight_smile: but gives null values when I run all of them.

But the node works after using the Material Create and Add AppearanceAssetElement node.

Thanks all!

Hey everyone. I’d love to see the complete script as well, if possible. Great solution to an annoying problem. /E

I’d love to see the complete script too

ahhh so happy to see people automating materials. Well i am working on something similar and its best to double check the lacing sometimes.

Hi, I’m trying to redo the same thing as you, and I manage to achieve the same results in the English version, however in the French version I have major difficulties with making everything work.
I’m guessing it should be the “generic_diffuse” part that needs to be translated from the english to the french, but I cannot find what I should replace it with.
I don’t know python at all, I can guess how things work but idk where I could find the library of objects when I have such questions, can anyone points me in the right direction?

Regarding the other Dynamo librariers, I tried both Orchid and Genius Loci, and I’m having problems at the same point, when I need to change the colors of the material appearance asset, I have no idea how to do it, cause the language changes the labels I should put in…

Hi,
Please start a new thread and show a screenshot of your graph. You can link this topic as a reference.

I’m guessing it should be the “generic_diffuse” part that needs to be translated from the english to the french

I created the Genius Loci nodes on a french Revit version so it’s not a matter of translating in french the code.