Exporting multiple materials, each to an rmtl file

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

for rm in sc.doc.RenderMaterials: print rm.Name
1 Like

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

Best regards,
Masaki

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

1 Like