LOPs - assign materials based on names

// Automatically assigning shaders based on names
// define material list

string matList[] = usd_childnames(0, chs("materialPath"));
string newMatList[] ;
string primList[] = usd_childnames(0, chs("geoPath"));
string primListFinal[];
string primname = @primname;
// recreating the order of the shaders on the elmnum array list
string fMatList[] ;

// define material list size
int matSize = len(matList);

// rename materials name to match with primitives
foreach (int i; string name; matList) {
string strMatList = matList[i];
// printf(strMatList+"\n");
string strMatListTwo = replace(strMatList,"_mat","");
append(newMatList[i], strMatListTwo);
// printf(newMatList[i]+"\n");
}

// run through all prims in geo
string spp;
spp = @primpath ;
primList = split(spp, " ");

foreach (int j; string pname; primList){
string tempList = primList[j];
primListFinal = split(tempList, "/");
// printf(primListFinal[-1]+"\n");
// find the right index order between the mat and prim array lists
int index = find(newMatList, primListFinal[-1]);
if (index >= 0 && fMatList[j] != "default") {
append(fMatList[j], newMatList[index]);
} else {
append(fMatList[j], "default");
}
// printf(fMatListt[j]+" ");

return (@elemnum) ? "/materials/"+fMatList[j]+"_mat" : "/materials/default_mat";
}