Created
June 13, 2021 22:37
-
-
Save orels1/2405f2fbc6a3b0950b8f65881db1b567 to your computer and use it in GitHub Desktop.
Blender Addon: Batch Smart Unwrap
This file contains 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 characters
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
Can you edit this so that it uses the default Unwrap?
Also if possible, it will keep the settings you use? I see here it sets some specific settings for the Smart UV Project, but I want to do a normal Unwrap with a 0.04 margin.
I managed to do it myself, by changing line 34 and 35 to simply bpy.ops.uv.unwrap()