Skip to content

Instantly share code, notes, and snippets.

@sambler
Last active October 6, 2020 08:27
Show Gist options
  • Save sambler/d8384a36ef07d33010574d3a104b1e42 to your computer and use it in GitHub Desktop.
Save sambler/d8384a36ef07d33010574d3a104b1e42 to your computer and use it in GitHub Desktop.
uvunwrap a blender object using a script
# save this as uvproject.py and use the following command
# blender -b test.blend -P uvproject.py
import bpy
# Deselect all
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
obj.select_set(state=True)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
if len(obj.data.uv_layers) == 0:
obj.data.uv_layers.new()
bpy.ops.uv.smart_project()
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.wm.save_mainfile()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment