r/Maxscript • • Jun 06 '26

Hi everyone, somebody know how to create a 3ds max script that assigns selected materials to objects with the same name?

2 Upvotes

13 comments sorted by

1

u/Valuable_Bed_5282 Jun 07 '26

Great! thx a lot it works. If I want apply the script without select the materials before?

1

u/Butthead128 Jun 07 '26 edited Jun 07 '26

My script does not care about material selection in SME, it just collects list of ALL materials in your scene, then for every material it checks if there is an object with that name and assigns this material to that object.

1

u/Valuable_Bed_5282 Jun 07 '26

I tried your but it doesn't work

1

u/Butthead128 Jun 07 '26

I've set more accurate code tagging in my previous post.
Should work this time.

1

u/Valuable_Bed_5282 Jun 07 '26

I'll try it, thank you very much, you are very kind

1

u/Valuable_Bed_5282 Jun 07 '26

thanks a lot! it works! it's more essential and direct, it works perfectly. thanks again

1

u/Butthead128 Jun 08 '26

Have fun. You can also put this code into macro and assign it to a hotkey or put it into your interface.

1

u/Valuable_Bed_5282 Jun 08 '26

yes I create a button with an hotkey, it help me very much. Thank you again.

1

u/Butthead128 Jun 07 '26 edited Jun 07 '26
scenematerialsArr = #()
for cclass in material.classes do
(
  currentMatArr = getClassInstances cclass
  scenematerialsArr += currentMatArr
)
for cMat in scenematerialsArr do
(
  targetNode = getNodeByName cMat.name
  if targetNode != undefined do targetNode.material = cMat
)

1

u/Valuable_Bed_5282 Oct 16 '26

hi Butthead128, I am truly grateful to you for your script, unfortunately it works just the first import then when I import again the same objects it no longer works. Have you some idea why it's happen?

1

u/Butthead128 Oct 30 '26

No idea. If this thing is really vital for your work, contact me directly,
we will arrange a remote control session on your side and will try to fix this.
You can find my contacts on my homepage:
pogribniy.net.ua

1

u/Valuable_Bed_5282 Nov 01 '26

the solution was so simple, just select all materials and set 'put material to scene', anyway thank you a lot

1

u/piXelicidio Jun 07 '26

function getSelectedSmeMaterials = (

if not sme.IsOpen() do return #()

local activeView = sme.GetView sme.activeView

local selectedNodes = activeView.GetSelectedNodes()

for n in selectedNodes where isKindOf n.reference Material collect n.reference

)

function assignMaterialsToMatchingObjects matList = (

for mat in matList do (

for obj in objects where obj.name == mat.name do (

obj.material = mat

)

)

)

selectedMats = getSelectedSmeMaterials()

assignMaterialsToMatchingObjects selectedMats