Created
June 13, 2021 22:37
-
-
Save orels1/2405f2fbc6a3b0950b8f65881db1b567 to your computer and use it in GitHub Desktop.
Revisions
-
orels1 created this gist
Jun 13, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ 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()