# Exporting multiple materials, each to an rmtl file

**URL:** <https://discourse.mcneel.com/t/exporting-multiple-materials-each-to-an-rmtl-file/99314>\
**Category:** Rhino Developer\
**Tags:** python, windows10\
**Created:** [April 2, 2020, 2:52am UTC](https://discourse.mcneel.com/t/exporting-multiple-materials-each-to-an-rmtl-file/99314 "2020-04-02T02:52:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11159](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11159/32/765292_2.png) [@11159](https://discourse.mcneel.com/u/11159)\
**Post date:** [April 2, 2020, 2:52am UTC](https://discourse.mcneel.com/t/exporting-multiple-materials-each-to-an-rmtl-file/99314/1 "2020-04-02T02:52:09Z")

</div>

Hello, everyone.

I use Rhino6 (Windows 10 Rhino6 SR24) and I want to export each of the multiple materials to an rmtl file.  
Of course, I can export one by one, but I’d like to be able to export one at a time with a script or something.

In Rhino6, I could export to rmtl with the [-Materials] command, so I was able to export a named material with the following script.

===========================================================================  
# -_- coding: utf-8 -_-

```
import rhinoscriptsyntax as rs
rs.Command('! _-Materials _Options _SaveToFile "Glass" "C:\export\Glass_export.rmtl" _Enter _Enterend')

```

===========================================================================

But in this way, I have to specify the material’s name or ID, respectively.  
How can I select the names or ID of existing materials?

```
import scriptcontext as sc
sc.doc.RenderMaterials		

```

??

Best regards,  
Masaki

---

<div class="post-metadata">

**Author:** ![nathanletwory](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/nathanletwory/32/482880_2.png) [@nathanletwory](https://discourse.mcneel.com/u/nathanletwory)\
**Post date:** [April 2, 2020, 4:33am UTC](https://discourse.mcneel.com/t/exporting-multiple-materials-each-to-an-rmtl-file/99314/2 "2020-04-02T04:33:17Z")

</div>

```python
for rm in sc.doc.RenderMaterials: print rm.Name

```

---

<div class="post-metadata">

**Author:** ![11159](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11159/32/765292_2.png) [@11159](https://discourse.mcneel.com/u/11159)\
**Post date:** [April 2, 2020, 5:40am UTC](https://discourse.mcneel.com/t/exporting-multiple-materials-each-to-an-rmtl-file/99314/3 "2020-04-02T05:40:53Z")

</div>

Thank you for your quick response!  
I could get the name of the material.

Best regards,  
Masaki

---

<div class="post-metadata">

**Author:** ![11159](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/11159/32/765292_2.png) [@11159](https://discourse.mcneel.com/u/11159)\
**Post date:** [April 2, 2020, 7:40am UTC](https://discourse.mcneel.com/t/exporting-multiple-materials-each-to-an-rmtl-file/99314/4 "2020-04-02T07:40:26Z")

</div>

Thank you so much for your reply.  
I was able to export each of the materials to an rtml file with a script like the one below.

I’m not a programmer, so please forgive me if the script is oddly written.

```
# -*- coding: utf-8 -*-

import rhinoscriptsyntax as rs
import scriptcontext as sc
import os.path as path

for rm in sc.doc.RenderMaterials:
    filePath = path.abspath('C:\export\\' +rm.Name + '.rmtl')
    lineString = '! _-Materials _Options _SaveToFile "{0}" "{1}" _Enter _Enterend'.format(rm.Name,filePath)
    rs.Command(lineString)

```

Best regards,  
Masaki
