Create Materials with Appearance color value using GeniusLoci package

package
revit
dynamo
#1

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
#2

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
#3

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
#4

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:

#5

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

#6

and here’s the flattened version:

here’s a more complete graph:

1 Like
#7

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 ?

#8

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
#9

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

#10

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

#11

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!