Announcement

Collapse
No announcement yet.

Script to rename materials based on geo name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to rename materials based on geo name

    Im looking for a script to take a bunch of objects and rename their assigned materials to match the name of the object it's applied to.

    Is there something like this already out there? (ive not been able to find it)

    How would I script this? (bit of a newbie with scripting)

    Any help super appreciated

  • #2
    Closest I've come to this is using 'Detach by ID' script. I'd combine the entire scene into a single mesh and then run this script to datach by 'material name' - I believe it includes the material name in the new object's name when everything is broken up.
    Brendan Coyle | www.brendancoyle.com

    Comment


    • #3
      Ah, that could work.
      May even be a better way to do it as I can then separate all the objects by material but in larger groups.

      Comment


      • #4
        What happens if two objects have the same material?
        Maxscript made easy....
        davewortley.wordpress.com
        Follow me here:
        facebook.com/MaxMadeEasy

        If you don't MaxScript, then have a look at my blog and learn how easy and powerful it can be.

        Comment


        • #5
          Originally posted by Dave_Wortley View Post
          What happens if two objects have the same material?
          Ultimately they should be collapsed to one object, if they have the same mat

          After some trial and error, essentially what Im looking for is something to explode everything by material, and then collapse everything by material, so I end up with one object per material.

          Comment


          • #6
            Using it for texture baking and export.
            Found this script which replaces the shell material with the baked standard material, but I cant work out why it gives it the name of the baked material rather than the shell material?

            If go in the listener and do

            m=$.material

            m.name

            Then i get the name of the Shell material, not the baked material, so not sure why this script does something different.

            Code:
            for o in geometry do
            
            (
            if classof o.material == Shell_Material then
            (
            
            m = o.material
            
            newmat = StandardMaterial name: m.name
            
            newMat = m.bakedMaterial
            
            o.material = newMat
            )
            )

            Comment


            • #7
              You shouldn't need a script to replace the shell material with the baked material. In the Render to Texture window, at the bottom you can select 'keep baked materials' and click clear shell materials.
              Brendan Coyle | www.brendancoyle.com

              Comment


              • #8
                Originally posted by cheerioboy View Post
                You shouldn't need a script to replace the shell material with the baked material. In the Render to Texture window, at the bottom you can select 'keep baked materials' and click clear shell materials.
                Yeah but it does the same thing, keeps the name of the baked material rather than the shell.

                Regardless, I definitely feel like Im going the long way around................

                Comment


                • #9
                  Ah, gotcha. Yeah that would be convenient if the mesh names could match the material's applied! I think for myself I just used the mesh names to find the attached shaders I'd need to tweak.
                  Brendan Coyle | www.brendancoyle.com

                  Comment

                  Working...
                  X