Hello,
I am new to maxScript. I am looking for a script that will rename only my selected material.
Samethink like this:
macroScript RenameThem category: "HowTo"
(
rollout rename_rollout "Enter New Base Name"
(
edittext base_name ""
button rename_them "RENAME SELECTED OBJECTS..."
on rename_them pressed do
(
if base_name.text != "" do
for i in selection do i.name = uniquename base_name.text
)--end on
)--end rollout
createDialog rename_rollout 250 50
)
But this only works on an object.
This works for all my material:
for mat in scenematerials do
(
print ("material name: " + mat.name)
mat.name = "_512_opaque"
)
So i need only the selection from the scenematerials array.
Hope sameone can help
Greetings Peter
Solved! Go to Solution.
Solved by denisT.MaxDoctor. Go to Solution.
fn collectMaterials nodes =
(
/* collect all valid materials that used with the specified list of nodes */
mats = for node in nodes where node.material != undefined collect node.material
/* make the list of materials unique to avoid re-naming the same materials */
makeuniquearray mats
)
/* mapped functions work for a single input and a "collectable" input argument */
mapped fn renameMaterial mat prefix: postfix: =
(
if iskindof prefix String do mat.name = prefix + mat.name
if iskindof postfix String do mat.name = mat.name + postfix
ok
)
-- using:
mats = collectMaterials selection
renameMaterial mats postfix:"_512_opaque"
see MXS help for more information .. or ask questions here if you have
Thank for your script and explanation. I wanted to select the materials in the slate material editor but this also works.
The postfix and prefix is really nice and understandable but i needed to clear the naming field and only put my naming there but i fixed that.
Thank you,
Greetings Peter
fn sme_getSelectedMaterials view: =
(
if view == unsupplied do view = sme.getview sme.activeview
tv = trackviewnodes[#sme]
vsub = tv[view.name]
for k=1 to vsub.numsubs collect
(
sub = vsub[k]
ref = sub.reference
node = view.getnodebyref ref
if node.selected and iskindof ref Material then ref else dontcollect
)
)
mapped fn renameMaterial mat name: prefix: postfix: =
(
name = if iskindof name String then name else mat.name
if iskindof prefix String do name = prefix + name
if iskindof postfix String do name = name + postfix
mat.name = name
ok
)
mats = sme_getSelectedMaterials()
I added how to get selected materials from SME, and modified rename material function to be able to set new name as well.
Hello DennisT,
This script is even better it is doing exacly what i had in mind.
I included a last line:
renameMaterial mats name:"naam_opaque"
This realy help in automating my workflow.
Greetings Peter
Can't find what you're looking for? Ask the community or share your knowledge.