# Set Material Parameters from Python Script

**URL:** <https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668>\
**Category:** Developers\
**Tags:** python\
**Created:** [September 8, 2017, 3:13pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668 "2017-09-08T15:13:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![danny.debinski](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/danny.debinski/32/31847_2.png) [@danny.debinski](https://forum.dynamobim.com/u/danny.debinski)\
**Post date:** [September 8, 2017, 3:13pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/1 "2017-09-08T15:13:17Z")

</div>

Hi everyone, I’m a newcomer to the Bim/Revit/Dynamo world, so please excuse my ingenuity beforehand.  
My new task is to prepare about 5000 materials, which are pretty similar one to another.  
After a few days creating everything manually, decided give Dynamo a chance to do that for me.  
Did my (quick) research on internets, found the script for creating materials with python, modified it to suit my needs.  
It creates the materials in revit, but I can’t find the way to set material properties from within it,  
gives me following error `"TypeError: 'ParameterSet' object is unsubscriptable"`

Here’s the script:

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
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 ToDynamoObject(revitObject, isRevitOwned=False): 
     # isRevitOwned should be False if Dynamo script created the object.
     return revitObject.ToDSType(isRevitOwned)

doc = DocumentManager.Instance.CurrentDBDocument
#Las entradas de este nodo se almacenan como lista en las variables IN.
dataEnteringNode = IN

#Asigne la salida a la variable OUT.
OUT = 0
newMaterials = []

for mat_list in dataEnteringNode:
    for id, fmt, gr, din, mat_name, aspect_name, comments, url in mat_list:
        TransactionManager.Instance.EnsureInTransaction(doc)
        mat_name_r = mat_name.replace('"','')
        mat_name_t = mat_name_r.strip()
        new_mat_id = Material.Create(doc, mat_name_t)
        new_mat = doc.GetElement(new_mat_id)
        #new_mat.MaterialClass("Wood")
        #new_mat.Transparency = transparency
        #new_mat.URL = url
        new_mat.Parameters['URL'] = url
        #elem = UnwrapElement(new_mat)
        #elem.Parameters['URL'] = url
        TransactionManager.Instance.TransactionTaskDone()
        #newMaterials.append(ToDynamoObject(new_mat))
        newMaterials.append(new_mat)
        #newMaterials.append(ToDynamoObject(new_mat.Properties))        
OUT = newMaterials

```

As you can see, I’ve tried a few possibilities, but none of them worked.

Or setting material properties member is similar to following snippet (found here: [modify-the-material-thermalconductivity-parameter](https://forum.dynamobim.com/t/modify-the-material-thermalconductivity-parameter/4671?u=danny.debinski)) :

```
thermalAssetID = material.ThermalAssetId
propertySetElement = doc.GetElement(thermalAssetID)
thermalass = propertySetElement.GetThermalAsset()
thermalass.ThermalConductivity = thermalcond 

```

Any link (to) manual, tutorial or a few lines of code will by highly appreciated.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 8, 2017, 6:55pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/2 "2017-09-08T18:55:55Z")

</div>

What Revit version are you in?

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [September 8, 2017, 8:08pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/3 "2017-09-08T20:08:31Z")

</div>

Did you also see this thread?

> [@Create new material + thermal & physical properties using Dynamo: How?](https://forum.dynamobim.com/t/create-new-material-thermal-physical-properties-using-dynamo-how/4365/2):
>
> You can create material with python-script node. Like this: How to fill thermal & physical properties - this my problem too =(

---

<div class="post-metadata">

**Author:** ![danny.debinski](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/danny.debinski/32/31847_2.png) [@danny.debinski](https://forum.dynamobim.com/u/danny.debinski)\
**Post date:** [September 11, 2017, 8:02am UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/4 "2017-09-11T08:02:25Z")

</div>

It’s Revit 2015

I was able to access the parameters with:

```
for param in new_mat.Parameters:
    newMaterials.append(param.URL)
    #or
    newMaterials.append(param['URL']) 

```

But

```
'Parameter' object has no attribute 'URL' or
TypeError: 'Parameter' object is unsubscriptable

```

happens. The [Revit 2015 API](http://www.revitapidocs.com/2015/ed0215e3-61d3-6a11-0152-e3be4e9d8913.htm) does not enumerate parameter names 😕

---

<div class="post-metadata">

**Author:** ![danny.debinski](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/danny.debinski/32/31847_2.png) [@danny.debinski](https://forum.dynamobim.com/u/danny.debinski)\
**Post date:** [September 11, 2017, 8:18am UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/5 "2017-09-11T08:18:32Z")

</div>

It was one of the firsts post I followed,  
the thing is I would like to set the properties in the Identity tab first (Descriptive Information and Product Information), .  
From the Graphics Tab check the ‘use render appereance’ checkbox,  
the Appereance Tab name and comments , the image can be/should be managed manually.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 11, 2017, 11:27am UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/6 "2017-09-11T11:27:10Z")

</div>

Still not sure what exactly parameters you’re trying to manage with dynamo, but there are a bunch of new API functions for materials in Revit 2018.1.

> **[Revit 2018.1 and the Visual Materials API](https://thebuildingcoder.typepad.com/blog/2017/08/revit-20181-and-the-visual-materials-api.html)**
>
> The Revit 2018.1 update was released last month.
> It implements one of the most important and long-standing API wishes, providing programmatic access to materials
> – Dynamo Player improvements
> – Visual Materials API
> – Fabrication parts centre line...

May be that you need to upgrade a bit to accomplish this.

---

<div class="post-metadata">

**Author:** ![danny.debinski](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/danny.debinski/32/31847_2.png) [@danny.debinski](https://forum.dynamobim.com/u/danny.debinski)\
**Post date:** [September 11, 2017, 12:28pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/7 "2017-09-11T12:28:52Z")

</div>

You’re right, I didn’t explain myself clearly.

I’d like to set these with PythonScript:

 ![revit-parameters](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/c/cc73f40f9c5b49a9db7e7bf3b1e38932630d0c3d.jpg) ![revit-parameters-2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/b/fb796a7232a6e63609964c9df0ad4a9a0963d078.jpg)

Saw one user setting them with `Element.SetElementByName` here:

([how-to-set-the-material-parameters-class-and-keywords](https://forum.dynamobim.com/t/how-to-set-the-material-parameters-class-and-keywords/4392))

and I thought it will be possible with python.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 11, 2017, 12:40pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/8 "2017-09-11T12:40:35Z")

</div>

Identity tab stuff is doable. Well maybe not all of it but I know some of it is as that was my first ever script.

Element.setparameterbyname is all you need so long as you feed the right elements (materials) and value types.

The appearance tab you can’t touch unless you are in Revit 2018.1.

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [October 5, 2017, 3:10pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/9 "2017-10-05T15:10:48Z")

</div>

Trying to break through some mysteries here, I discovered some interesting things. I am on R2017 at the moment:

- First, the color of a material (the one from the Graphics tab) can be set with a simple _Element.SetParameterByName_ node. The awaited value is an integer but I don’t know how this number is defined. I have been able to set a value from 0 up to 16777215.
- Second, the whole Appearance tab can be set by switching the material asset element with _Material.SetMaterialAssetByAssetId_ or _Material.SetMaterialAssetByMaterial_ from Archi-lab\_Grimshaw, but I assume that this has already been exposed somewhere.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 5, 2017, 3:21pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/10 "2017-10-05T15:21:13Z")

</div>

> [@Yna\_Db](#):
>
> The awaited value is an integer but I don’t know how this number is defined. I have been able to set a value from 0 up to 16777215

It’s based on the RGB values; 256 options per variable.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/b/8b34f48f5ee07f8b12e6c8cc5c13750d46bf4284.png)

```
r = dynColor.Red;
g = dynColor.Green;
b = dynColor.Blue;

integer = r+256*g+65536*b;

```

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [October 5, 2017, 3:27pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/11 "2017-10-05T15:27:09Z")

</div>

Any link to an additional resource about that, by chance?

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 5, 2017, 3:38pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/12 "2017-10-05T15:38:15Z")

</div>

Afraid not. It was just from experimenting with integers and the resulting RGB values.  
Here’s how it breaks down:

Red takes up integers 0-255. Makes sense.  
Green starts at 256 but begins counting with the Red values. So 256 = [R=0,G=1,B=0] and 257 = [R=1,G=1,B=0] and so on.  
Blue starts at 65536 and follows the same pattern of counting the Red value first, followed by Green, then finally Blue.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [October 5, 2017, 4:12pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/13 "2017-10-05T16:12:25Z")

</div>

I think springnodes has a custom node for this.

---

<div class="post-metadata">

**Author:** ![andres.lara4NVFA](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@andres.lara4NVFA](https://forum.dynamobim.com/u/andres.lara4NVFA)\
**Post date:** [February 6, 2018, 1:39pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/14 "2018-02-06T13:39:58Z")

</div>

using element unique id, you can set all parameter of materials

 ![ej%20item](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/4/047a82eac9d3400eeb726402bbe0913d08139591.PNG)

---

<div class="post-metadata">

**Author:** ![wma\_sfenton](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@wma\_sfenton](https://forum.dynamobim.com/u/wma_sfenton)\
**Post date:** [June 18, 2018, 8:49pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/15 "2018-06-18T20:49:42Z")

</div>

Were you able to complete this script? I am trying to accomplish something similar where our material database is in excel!

---

<div class="post-metadata">

**Author:** ![danny.debinski](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/danny.debinski/32/31847_2.png) [@danny.debinski](https://forum.dynamobim.com/u/danny.debinski)\
**Post date:** [July 10, 2018, 8:32am UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/16 "2018-07-10T08:32:23Z")

</div>

Sorry for late response, but I’ve abandoned the idea of doing this with python and switched to c#. With VS you can connect directly to RevitSDK and contextual help there works very well.

---

<div class="post-metadata">

**Author:** ![rahim.rajpari](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@rahim.rajpari](https://forum.dynamobim.com/u/rahim.rajpari)\
**Post date:** [August 12, 2019, 11:42am UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/17 "2019-08-12T11:42:51Z")

</div>

Hello,

I have created few project parameters by **“Parameter.CreateProjectParameter”** for the category “Materials”. now I’m trying to set these parameter values and I cant achieve it through **“Element.SetPararmeterByName”**.

 ![Query](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/c/1c3e8b8471df2fea908a65cf443f173852c5341d.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 12, 2019, 11:50am UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/18 "2019-08-12T11:50:36Z")

</div>

You’re feeding the parameter a string, and it wants something else (not sure what as I don’t see where you made the parameter here). Try a double or integer, if that fails start a new topic and include your graph and a sample rvt file.

---

<div class="post-metadata">

**Author:** ![rahim.rajpari](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@rahim.rajpari](https://forum.dynamobim.com/u/rahim.rajpari)\
**Post date:** [August 13, 2019, 8:22pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/19 "2019-08-13T20:22:33Z")

</div>

Thanks Jacob. You were right. I was setting these new parameters type to “Number” and that’s why it was not taking input of a “String”. Now I have the parameter type to “Text” and it takes input from both numbers and strings.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![rahim.rajpari](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@rahim.rajpari](https://forum.dynamobim.com/u/rahim.rajpari)\
**Post date:** [August 29, 2019, 5:28pm UTC](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/20 "2019-08-29T17:28:07Z")

</div>

Is there a way to set multiple parameters of multiple elements?

Just Like this but with multiple elements

> [@Set Material Parameters from Python Script](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668/17):
>
> Hello, I have created few project parameters by “Parameter.CreateProjectParameter” for the category “Materials”. now I’m trying to set these parameter values and I cant achieve it through “Element.SetPararmeterByName”.

[Next page](https://forum.dynamobim.com/t/set-material-parameters-from-python-script/14668.md?page=2)
