0
$\begingroup$

I have a tool that I've written that takes blend files and converts them into quake 3 maps. This automates a ton of stuff that saves me a lot of time, but there's still several tedious steps before getting to that. One of those steps is splitting complex meshes up and generating textures and materials for each object. To keep things simple for editing, I'd like to have object name, mesh name, material name and texture name be the same for each object.

To accomplish this, I've found and used the batch rename data blocks script located here. For how great this script is, there's one thing it lacks, that being the ability to rename the active or first texture for the materials. I've attempted to access material.texture_slots[n].name and change this value, but got an error that it was read-only.

What is the appropriate api/process to rename images attached to materials? For what it's worth, all images are packed, generated textures.

$\endgroup$
2
  • 1
    $\begingroup$ While the script you mention doesn't appear to be updated you should look in the new contrib addons git repo instead of the old svn one. $\endgroup$
    – sambler
    Commented Sep 14, 2015 at 13:01
  • $\begingroup$ @sambler thanks for pointing that out. :) $\endgroup$
    – user1745
    Commented Sep 14, 2015 at 13:24

1 Answer 1

2
$\begingroup$

I realize I just posted the question but I solved this myself not long after. You can also rename the texture names and texture image names with this script by modifying the block of code that renames materials like so:

        if self.rename_material:
            if ob.material_slots:
                for m_slot in ob.material_slots:
                    if m_slot.material:
                        if m_slot.material.users == 1:
                            if (self.rename_use_prefix
                            and self.prefix_material):
                                m_slot.material.name = self.rename_prefix + name
                            else:
                                m_slot.material.name = name
                        if m_slot.material.texture_slots:
                            ~~~~VVV Added The Following VVV~~~
                            if(len(m_slot.material.texture_slots) > 0):
                                m_tex = m_slot.material.texture_slots[0]
                                m_tex.texture.name = name
                                m_tex.texture.image.name = name

Obviously there's some checks that could be done such as number of users and such. I'll post back as I polish the script.

$\endgroup$
1
  • $\begingroup$ "I'll post back as I polish the script." -- And yet, this never happens, as expected. :-) $\endgroup$ Commented Mar 22, 2017 at 20:49

You must log in to answer this question.