Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 2_80 #2

Open
Weisl opened this issue Feb 19, 2019 · 4 comments
Open

Port 2_80 #2

Weisl opened this issue Feb 19, 2019 · 4 comments

Comments

@Weisl
Copy link

Weisl commented Feb 19, 2019

Hi,
I ported your addon to blender 2_80. I needed it and it took me about 10 minutes. I would contribute my change to you if I would know how. I am not really experienced with github, so I don't know if I am doing something wrong or if I don't have any permission to make pull requests.
Anyway, I can send you the updated version at any time.

and thanks for the addon in general :)!

@ekaj2
Copy link
Owner

ekaj2 commented Feb 20, 2019

@Weisl Thanks. It's only a short one-file add-on, so if you want, you can just paste it into a comment on this issue and format it as code by putting ``` on blank lines before and after it. If you type ```python for the first one, it should show up with Python syntax highlighting. I can include it if I get around to it...I'd want to do my own tests a bit, but then at least folks can use it ATM if they wish.

@Weisl
Copy link
Author

Weisl commented Feb 26, 2019

Sorry, completely forgot to upload it :D.

# Copyright 2016 Jake Dube
#
# ### BEGIN GPL LICENSE BLOCK ###
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ### END GPL LICENSE BLOCK ###

import bpy
from bpy.types import Operator

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


def make_active(name):
    uvs = bpy.context.view_layer.objects.active.data.uv_layers
    for uv in uvs:
        if uv.name == name:
            uvs.active = uv
            return
    print("Could not find:", name, "\n(this should never happen)")


def move_to_bottom(index):
    uvs = bpy.context.view_layer.objects.active.data.uv_layers
    uvs.active_index = index
    new_name = uvs.active.name

    bpy.ops.mesh.uv_texture_add()

    # delete the "old" one
    make_active(new_name)
    bpy.ops.mesh.uv_texture_remove()

    # set the name of the last one
    uvs.active_index = len(uvs) - 1
    uvs.active.name = new_name


class UV_OT_MoveUVMapDown(Operator):
    bl_idname = "uv_tools.move_uvmap_down"
    bl_label = "Move Uv Set Down"
    bl_options = {"REGISTER", "UNDO"}

    def execute(self, context):
        uvs = bpy.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'}

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

        # use the "trick" on the UV map
        move_to_bottom(orig_ind)

        # use the "trick" on the rest that are after where it was
        for i in range(orig_ind, len(uvs) - 2):
            move_to_bottom(orig_ind)

        make_active(orig_name)

        return {'FINISHED'}


class UV_OT_MoveUVMapUp(Operator):
    bl_idname = "uv_tools.move_uvmap_up"
    bl_label = "Move Uv Set Up"
    bl_options = {"REGISTER", "UNDO"}

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

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

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

        return {'FINISHED'}


def uv_tools_addition(self, context):
    layout = self.layout
    col = layout.column(align=True)
    col.operator("uv_tools.move_uvmap_up", icon='TRIA_UP')
    col.operator("uv_tools.move_uvmap_down", icon='TRIA_DOWN')


def register():
    bpy.utils.register_class(UV_OT_MoveUVMapDown)
    bpy.utils.register_class(UV_OT_MoveUVMapUp)
    bpy.types.DATA_PT_uv_texture.append(uv_tools_addition)


def unregister():
    bpy.utils.unregister_class(UV_OT_MoveUVMapDown)
    bpy.utils.unregister_class(UV_OT_MoveUVMapUp)
    bpy.types.DATA_PT_uv_texture.remove(uv_tools_addition)



@iSenChi
Copy link

iSenChi commented Apr 5, 2020

Can't make it works for 2.83 :(

@Weisl
Copy link
Author

Weisl commented Apr 8, 2020

I just tested my updated script from above in blender 2.83 and it worked. Can you provdie further information what doesn't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants