Create new material + thermal & physical properties using Dynamo: How?

Please any nodes can ce used to create a new materials inside Revit material library using Dynamo and fill its thermal & physical properties using Dynamo as well !!
Thanks!!

1 Like

You can create material with python-script node. Like this:

How to fill thermal & physical properties - this my problem too =(

Please!! Could you copy this code for me :slight_smile:

Code:

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
TransactionManager.Instance.EnsureInTransaction(doc)
Material.Create(doc,"New")
TransactionManager.Instance.TransactionTaskDone()

You can use any methods from api. Link_to_Revit_API

2 Likes

Thank you my friend :slight_smile:

Is there a way of adding an input to this script so that you can input a list of Material Names and it will create new materials from this list?

I know I may be asking a bit much, but can it also assign a different shading colour to these materials?

Thanks for any help,

Yes you can use list as input. It will be loop operation in Python-node to create different materials.
You can change shading color through AppearanceAssetId property of material.

Hi @catexis
This is very interesting subject I would like to see script that can create new materials from list together with thermal properties and color…so In one go we could generate required construction

1 Like

@Michal_Dengusiak I was intrigued about this as well, seems like it could be a helpful definition to create materials dynamically.

I did a quick test; would be easy to extend it to include other Properties.

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

names = IN[0]
transparencies = IN[1]

for mat_name, transparency in zip(names, transparencies):
    TransactionManager.Instance.EnsureInTransaction(doc)
    new_mat_id = Material.Create(doc, mat_name)
    new_mat = doc.GetElement(new_mat_id)
    new_mat.Transparency = transparency
    TransactionManager.Instance.TransactionTaskDone()

Create Material:
http://www.revitapidocs.com/2015/5d8f8735-b814-5ac0-e8c5-114da8caa7bc.htm

Material Properties:
http://www.revitapidocs.com/2015/0c1ef2f6-706a-5681-b96e-38ad30cf788f.htm

5 Likes

Thanks, this will be perfect.

On the colour side…currently most of the colour creation tools in Dynamo are using the override in view option where as I think if there is a way of specifying a list of names and then using the colour range node to let Dynamo pick a colour in the range automatically, this will allow for the new material name list to vary in length, and the colours will automatically adjust.

So many practical applications!

Here is the finished product with the Material colours being added also.

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

names = IN[0]
transparencies = IN[1]
colors = IN[2]

newMaterials =

for mat_name, transparency, color in zip(names, transparencies, colors):
TransactionManager.Instance.EnsureInTransaction(doc)
new_mat_id = Material.Create(doc, mat_name)
new_mat = doc.GetElement(new_mat_id)
new_mat.Color = ToRevitColor(color)
new_mat.Transparency = transparency
TransactionManager.Instance.TransactionTaskDone()
newMaterials.append(ToDynamoObject(new_mat))

OUT = newMaterials

10 Likes

This is all very interesting. Is it possible to add a Material Keynote in addition to Name, Transparency and Color? I am currently trying to drive material creation within Revit from an Excel spreadsheet with the names and keynotes of materials.

Material Index_Keynotes.dyn (10.0 KB)

2 Likes

Hi Scott,

I can get the material and transparency script to work, but i cant seem to change the color with this script, i get the following warning

“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
expected an indented block”

Would you be able to post you script (or an image) of your workflow, so that I can see what is being utilised and fed into the node?

Guys it would be better if you can have conversations in new thread as this thread is decade ago. You can link this topic as a reference. Thanks :slight_smile: