Advertisement
loon4tic

batch uv export

Jan 14th, 2021
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. import bpy
  2. import os, subprocess, sys, re
  3.  
  4. class extractUV():
  5.     def __init__(self):
  6.         self.view_layer = bpy.context.view_layer
  7.         self.mFilePath = None
  8.         #scene = bpy.data.scenes.new("Scene")
  9.         bpy.ops.object.select_all()
  10.         bpy.ops.object.delete() # Delete the default stuff
  11.         pass
  12.        
  13.     def parseModel(self):
  14.         #bpy.ops.object.select_all(action='SELECT')
  15.         selection = bpy.context.selected_objects
  16.         bpy.ops.object.select_all(action='DESELECT')
  17.         if self.mFilePath is None:
  18.             return
  19.         for obj in selection:
  20.             self.obj = obj
  21.             obj.select_set(True)
  22.             self.view_layer.objects.active = obj
  23.             self.extractUV()
  24.             bpy.ops.object.delete()
  25.            
  26.     def extractUV(self):
  27.         if not bpy.context.object.data.uv_layers:
  28.             print(self.obj.name + " does not have UV map, skipping")
  29.         else:
  30.             exportPath = self.mFilePath + "_UV"
  31.             exportPath = "C:/Users/Azrael/Desktop/blender test stuff/" + obj.name
  32.             bpy.ops.uv.export_layout(filepath=exportPath, mode='PNG', opacity=45)
  33.    
  34.     def addModel(self, modelFilePath):
  35.         self.mFilePath = modelFilePath
  36.         bpy.ops.import_scene.obj(filepath=self.mFilePath) # maybe replace with glob
  37.    
  38. uv = extractUV()
  39.  
  40. os.chdir("C:/Users/Azrael/Desktop/Toontown/resources/")
  41. allFiles = []
  42. selectedPhases = ['5']
  43. inputFile = ".obj"
  44. for phase in selectedPhases:
  45.     if not os.path.exists('phase_%s' % phase):
  46.         continue
  47.     for root, _, files in os.walk('phase_%s' % phase):
  48.         for file in files:
  49.             if not file.endswith(inputFile): # Input file
  50.                 continue
  51.             file = os.path.join(root, file)
  52.             allFiles.append(file)
  53. for file in allFiles:
  54.     uv.addModel(file)
  55.     uv.parseModel()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement