ScriptSpot

Forum topic · Scripts Wanted

[REQ] Material ID Condense by PART of material name

By 1rv · 2017-08-30

Description

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 (1)

jahman · 2017-09-10

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
        )
    ) 
)