Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions uv_map_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

bl_info = {
"name": "UV Tools",
"author": "Jake Dube, cdeguise, bovesan",
"author": "Jake Dube, cdeguise, bovesan, Mahrkeenerh",
"version": (1, 1),
"blender": (2, 80, 0),
"location": "UV maps in properties window",
"description": "Some tools for uv maps that should already be in Blender.",
"category": "UV"}
"category": "UV"
}


def make_active(name):
Expand All @@ -38,7 +39,6 @@ def make_active(name):


def move_to_bottom(index):
# uvs = bpy.context.scene.objects.active.data.uv_textures
uvs = bpy.context.view_layer.objects.active.data.uv_layers
uvs.active_index = index
new_name = uvs.active.name
Expand All @@ -59,16 +59,32 @@ class MoveUVMapDown(Operator):
bl_label = "Move Down"
bl_options = {"REGISTER", "UNDO"}

@classmethod
def poll(cls, context):
if context.view_layer.objects.active is None:
return False
if context.view_layer.objects.active.type != 'MESH':
return False
if len(context.view_layer.objects.active.data.uv_layers) <= 1:
return False
if context.view_layer.objects.active.data.uv_layers.active_index >= len(context.view_layer.objects.active.data.uv_layers) - 1:
return False
return True

def execute(self, context):
uvs = context.view_layer.objects.active.data.uv_layers

# get the selected UV map
orig_ind = uvs.active_index
orig_name = uvs.active.name

if orig_ind == len(uvs) - 1:
return {'FINISHED'}

orig_name = uvs.active.name

# save active render map name
active_render_name = [uv.name for uv in uvs if uv.active_render][0]

# use "trick" on the one after it
move_to_bottom(orig_ind + 1)

Expand All @@ -81,6 +97,9 @@ def execute(self, context):

make_active(orig_name)

# restore active render map
uvs[active_render_name].active_render = True

return {'FINISHED'}


Expand All @@ -89,17 +108,35 @@ class MoveUVMapUp(Operator):
bl_label = "Move Up"
bl_options = {"REGISTER", "UNDO"}

@classmethod
def poll(cls, context):
if context.view_layer.objects.active is None:
return False
if context.view_layer.objects.active.type != 'MESH':
return False
if len(context.view_layer.objects.active.data.uv_layers) <= 1:
return False
if context.view_layer.objects.active.data.uv_layers.active_index <= 0:
return False
return True

def execute(self, context):
uvs = bpy.context.view_layer.objects.active.data.uv_layers

if uvs.active_index == 0:
if uvs.active_index <= 0:
return {'FINISHED'}

# save active render status
is_active_render = uvs.active.active_render

original = uvs.active.name
uvs.active_index -= 1
bpy.ops.uv_tools.move_uvmap_down()
make_active(original)

# restore active render status
uvs.active.active_render = is_active_render

return {'FINISHED'}


Expand Down