Notifications
Clear all
[Closed] Is there a Simple script to add prefix to materials
Jan 30, 2015 10:43 am
Hi, Im looking for a script that prefixes the max file name to every material name in a scene as well as names the multi subs and prefixes all of the id names in each multi sub and prefixes the max file name to each object name in the scene. Is anyone aware of a script that does something similar or one that i can edit to do what i want?
Thanks
Jack
4 Replies
Jan 30, 2015 10:43 am
Give this a try
theFileNamePrefix = (filterString maxFileName ".")[1]
for mat in scenematerials do
(
-- this line prefixes all scene materials
mat.name = (theFileNamePrefix+"_"+mat.name)
if classof mat == Multimaterial then
(
-- collect all the submtls
mysubmtls = #()
for a=1 to (getNumSubMtls mat) do
(
appendifunique mysubmtls (getSubMtl mat a)
)
-- rename the submaterials
for a=1 to mysubmtls.count do
(
-- this line prefixes the submaterials
mysubmtls[a].name = (theFileNamePrefix+"_"+mysubmtls[a].name)
)
-- rename multisubslots
for a=1 to (getNumSubMtls mat) do
(
if a <= 9 then theslotname = substring (getSubMtlSlotName mat a) 5 999
else theslotname = substring (getSubMtlSlotName mat a) 6 999
-- this line prefixes the slot names
mat.names[a] = (theFileNamePrefix+"_"+theslotname)
)
)
)
for myobject in objects do
(
-- this line prefixes all objects
myobject.name = (theFileNamePrefix+"_"+myobject.name)
)
Jan 30, 2015 10:43 am
That works great thanks! However it often throws an error on this line
mysubmtls[a].name = (theFileNamePrefix+"_"+mysubmtls[a].name)
unknown property ‘name’ on undefined.
1 Reply
The easiest way to avoid this error is to put that line in try()catch() statement.
try(mysubmtls[a].name = (theFileNamePrefix+"_"+mysubmtls[a].name))catch()
Jan 30, 2015 10:43 am
Do you maybe have multisubmaterials with empty slots? That could cause the problem.
Maybe i can write a fix, but for now just check for that.