I'd like to export UV sets for several objects which I need to be separated. Imagine one layer per object on a PSD file... right now im exporting the maps one by one but would like to try writing a script to at least do this in batch.
I've tried the answer by @HikariTW and the code almost works, but not properly. I've managed to solve a few errors, but the script is not working as intended.
It gets the active object, adds another one from the list and saves both objects UV's. Ideally the script should set one object from one collection to active, set it to Edit Mode, export it's uv map using the object name as the image name, set it back to Object Mode, select next and iterate.
I've tried to write the code I need from scratch using the suggested one as a reference but it's way over me:
import bpy import os # You should change this varibale in "here" to match your own directory path # use '/' or '\\' for hirecacy target_dir = "D:/directory/" selObj =  for obj in bpy.context.selected_objects: selObj.append(obj.name) bpy.ops.object.select_all(action='TOGGLE') i=0 while i < len(selObj): #line 18 does not work (AttributeError: bpy_prop_collection: attribute "active" not found) so i've updated it to 19-20 #bpy.context.scene.objects.active = bpy.context.scene.objects[selObj[i]] obj = bpy.context.window.scene.objects bpy.context.view_layer.objects.active = obj bpy.ops.object.mode_set(mode="EDIT") bpy.ops.mesh.select_all(action='TOGGLE') bpy.ops.mesh.select_all(action='TOGGLE') #no need for line 25 since objects have already been unwrapped #bpy.ops.uv.smart_project(angle_limit=66.0, island_margin=0.0, user_area_weight=0.0) full_file_name=target_dir + bpy.data.objects[selObj[i]].name # This code detected whether target_dir exist, if not, then create it dirname = os.path.dirname(full_file_name) if not os.path.exists(dirname): os.makedirs(dirname) bpy.ops.uv.export_layout(filepath=full_file_name, mode='PNG', size=(1024, 1024), opacity=0.6) bpy.ops.object.mode_set(mode="OBJECT") bpy.ops.object.select_all(action='TOGGLE') i+=1
Q: How can I make that work to export the maps for all objects?