i’m new to scripting in rhino and don’t know the right syntax yet.
Perhaps someone could help with one inconvenience.
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…
hi Will_Wang
how would the script look like if i want to replace a part of the material name?
that it works as search & replace solution?
in my case i need to delete the “/” at the first position of some material names.
I was trying to rename all my materials, i want to add a Prefix/suffix to all my materials and i was trying to use the below script.
import scriptcontext as sc
mats = sc.doc.Materials
for m in mats:
m.Name = ‘01_’+m.Name
m.CommitChanges()
The script runs with no errors but the prefix does not get applied to some materials, or is applied multiple times for some materials, would be helpful if someone could help me with this
Yup, that is because regular HTML rendering doesn’t preserve whitespace, with the exception of the <pre> tag, which is what is used to do code formatted bits.
Well true, but the script didn’t work for @Akazwarman_Balachand and does work once those errors are corrected so it’s reasonable to deduce that one or both were in the script before he posted it…
I see the problem description has changed (the deleted post which I acted on said no material names were changed). The corrected script amended all the materials in a file I tested it on as expected. The revision has muddied the waters and we need the poster’s file (preferably a copy from before the script was run) to understand the problem better.
Thank you, the script worked, but now i started having a different issue, few materials weren’t renamed and the other couple of materials had ‘01’ repated again and again. for example
" 01_01_01_01_Concrete". Any idea why this is happening ?