Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blender Addon: Batch Smart Unwrap
import bpy
bl_info = {
"name": "Batch Smart Unwrap",
"description": "Unwraps all the selected objects one by one using Smart UV Project.",
"author": "orels1 and Calo on blender StackExchange",
"version": (1, 0),
"blender": (2, 90, 0),
"category": "Object",
}
class BatchSmartUnwrap(bpy.types.Operator):
"""Batch Smart Unwrapper"""
bl_idname = "object.batch_smart_unwrap"
bl_label = "Smart Unwrap Selected Objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
selection_names = []
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
selection_names.append(obj)
obj.select_set(False)
if selection_names != []:
for obj in selection_names:
bpy.context.view_layer.objects.active = obj
if len(obj.data.uv_layers) == 0:
uv = obj.data.uv_layers.new(name="UVMap")
uv.active = True
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.smart_project(angle_limit=66.0, island_margin=0.2,
area_weight=0.0, correct_aspect=True, scale_to_bounds=False)
bpy.ops.object.editmode_toggle()
print(f"Smart Unwrapped {len(selection_names)} objects")
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(BatchSmartUnwrap.bl_idname)
def register():
bpy.utils.register_class(BatchSmartUnwrap)
# Adds the new operator to an existing menu.
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.utils.unregister_class(BatchSmartUnwrap)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment