[REQ] Material ID Condense by PART of material name

I digged all existing scripts in this field, nothing was a 100% working solution
Say I have multi/Sub-Object material
containing tons of sub-materials with almost identical names (the only diffrence is ENDING):
wood01, wood02.. woo999 etc.
Could you guys help me with script that condence ALL sub-materials by [part] of their names (defined by user (*woo* in this case)?
Many thanks in advance.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

..

This one will replace all similarly named materials with the instance of first one found.

pattern = "*woo*"
mtl = -- your multi-material goes here
mtls = mtl.materialList
mat = undefined
for i=1 to mtls.count where mtls[i] != undefined do (    
    if matchPattern mtls[i].name pattern:pattern do (        
        if mat == undefined then mat = mtls[i] else (        
            if mat != mtls[i] do mtls[i] = mat
        )
    ) 
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.