Add prefix/suffix to material names via script

Dear all,

i’m new to scripting in rhino and don’t know the right syntax yet.
Perhaps someone could help with one inconvenience. :wink:

I like to work with worksessions, but i am really bad in properly organizing the used materials in each file.
When it comes to combine them in a worksession there are multiple materials with names like “custom 01”. The first “custom 01” is a carpet, the next wood, the next simple black, and so on…

The problem is, that rhino assigns one material (texture, glossyness, whatever) to all “custom 01s”. So that now all “custom 01s” get a carpet texture.

Is there a simple way scripting a prefix to all file materials?

Means, i have file named 01_floor, 02_walls, 03_ceiling and i can rename all used materials in each file with the number prefix of the file, in order to get “01 custom 01” for the carpet, “02 custom 01” for the wood, “03 custom 01” for the simple black…

Anyone any idea?

Thank you very much!

Seb.

import scriptcontext as sc

mats = sc.doc.Materials
for m in mats:
    m.Name = '01_'+m.Name
    m.CommitChanges()

try this in python
if you need to revert back the changes replace first line of for loop with this:
m.Name = m.Name.strip('01_')

1 Like

Perfect! Thank you!