Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import bmesh
- import glob
- import shutil
- import os
- from pathlib import Path
- def run():
- #Check File
- path = bpy.path.abspath("//")
- path += "Textures"
- isFile = os.path.isdir(path)
- if not isFile:
- os.makedirs(path)
- print("Folder Created")
- else:
- print("File Already Exists")
- #Get the selected object
- obj = bpy.context.object
- #Get materials
- materials = obj.data.materials
- texture_list = []
- materialSlots = obj.material_slots
- for mat in materialSlots:
- print("~~Material: " + mat.name)
- if mat.material and mat.material.use_nodes:
- for texture in mat.material.node_tree.nodes:
- if texture.type == 'TEX_IMAGE':
- texture_list += [texture.image]
- tex = bpy.data.images[texture.image.name]
- full_path = bpy.path.abspath(tex.filepath, library=tex.library)
- norm_path = os.path.normpath(full_path)
- #print("~Texture Name: " + tex.name)
- #print("FullPath: " + full_path)
- #print("NormPath: " + norm_path)
- newLocation = path + '\\' + texture.image.name
- #print("New Location: " + newLocation)
- if os.path.isfile(norm_path) and not os.path.isfile(newLocation):
- temp = os.path.splitext(texture.image.name)
- print("_Split_")
- print(temp)
- fixedName = str(cleanName(temp))
- print("Fixed Name: " + fixedName)
- print(mat.name + " | uses: " + texture.image.name + " Location: " + texture.image.filepath)
- #newLocation = path + '\\' + mat.name + " - " + fixedName
- #print(newLocation)
- #shutil.copy(norm_path, newLocation)
- #texture.image = bpy.data.images.load(newLocation)
- elif os.path.isfile(norm_path) and os.path.isfile(newLocation):
- print("Already Exists: " + texture.image.name)
- else:
- print("File Missing: " + texture.image.name)
- print("")
- def cleanName(fileName):
- fileTypes = [".png",".jpg",".jpeg",".psd",".bmp",".gif",".dds",".tif",".tiff"]
- for extention in fileTypes:
- if fileName[1] == extention:
- name = fileName[0] + fileName[1]
- print("Cleaned Name: " + name)
- return name
- name = os.path.splitext(fileName[0])
- cleanName(name)
- def print(data):
- for window in bpy.context.window_manager.windows:
- screen = window.screen
- for area in screen.areas:
- if area.type == 'CONSOLE':
- override = {'window': window, 'screen': screen, 'area': area}
- bpy.ops.console.scrollback_append(override, text=str(data), type="OUTPUT")
- if __name__ == "__main__":
- print("~~~START OF CODE~~~")
- run()
- print("~~~END OF CODE~~~")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement