Material IDs are blank by default. This populates the blank names by copying the names of the current submaterial, ignoring undefined materials and slots that already have names in them.
Written in Max 2016, but should work in all other recent versions as well.

Comments (1)
Comment policy
Hello, this is really great thank you! Any chance you could make a version where it overwrites an existing material-ID name when you change the name of the corresponding material? As this only works by populating nameless slots, if you change a material name after running the script, you need to update the corresponding material-ID name manually. Would be great to have an overwrite feature.