-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename_texnodes.py
26 lines (21 loc) · 952 Bytes
/
rename_texnodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Used to sanitize material names and image names by renaming them to the name of the image file.
"""
import bpy
import os
def rename_texnodes():
for material in bpy.data.materials:
if material.node_tree:
for node in material.node_tree.nodes:
if node.type == 'TEX_IMAGE' and node.image:
# replace assets with // since that prolly implies its stored in the file itself
image_filepath = node.image.filepath.replace("//", "")
image_basename = os.path.basename(image_filepath)
image_filename = os.path.splitext(image_basename)[0]
new_material_name = f"{image_filename}"
material.name = new_material_name
new_image_name = f"{image_filename}"
node.image.name = new_image_name
break
rename_texnodes()
print("Conversion completed.")