1
$\begingroup$

This is a question that is an aside from my previous question of How to get name of image corresponding to active paint slot?

And in that question, I was looking to ultimately arrive at an Image Editor as a popup to use quickly while painting in 3d view that would immediately show the active paint slot to take advantage of the way that the Editor only shows one image at a time.

My own code from the previous post only gets the active texture to coincide with the current active paint slot, but by myself I did not get the popup editor to show it.

$\endgroup$
1
$\begingroup$

Blender does not support creating a new window officially. However, there is an obscure workaround: You can open up a new user preferences window and change its type to IMAGE_EDITOR, read: How to open an image editor window and display an image file in it?

In order to display the active paint slot in that window, just get the active image slot reference and then assign it to SpaceImageEditor.image. Following code is a simple operator, you can either install it like an Add-on or paste and run it in blenders text editor per session.

Blender 2.8x

enter image description here

bl_info = {
    "name": "Display active Slot",
    "description": "",
    "author": "brockmann",
    "version": (0, 0, 1),
    "blender": (2, 80, 0),
    "location": "Texture Paint > Tools Panel > Slots",
    "category": "Paint"
}

import bpy

class DisplayActivePaintSlot(bpy.types.Operator):
    '''Display selected paint slot in new window'''
    bl_label = "Display Active Slot"
    bl_idname = "paint.display_active_slot"
    bl_options = {'REGISTER'}

    @classmethod
    def poll(self, context):
        return context.object.active_material.texture_paint_images

    def execute(self, context):
        if context.object.active_material.texture_paint_images:
            # Get the Image
            mat = bpy.context.object.active_material
            image = mat.texture_paint_images[mat.paint_active_slot]
            # Call user prefs window
            bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
            # Change area type
            area = context.window_manager.windows[-1].screen.areas[0]
            area.type = 'IMAGE_EDITOR'
            # Assign the Image
            context.area.spaces.active.image = image
        else:
            self.report({'INFO'}, "No active Slot")
        return {'FINISHED'}

def draw_display_slot_operator(self, context):
    if context.object.active_material.texture_paint_images:
        layout = self.layout
        row = layout.row(align=True)
        row.operator(DisplayActivePaintSlot.bl_idname, icon='ZOOM_ALL')

def register():
    bpy.utils.register_class(DisplayActivePaintSlot)
    bpy.types.VIEW3D_PT_slots_projectpaint.prepend(draw_display_slot_operator)


def unregister():
    bpy.utils.unregister_class(DisplayActivePaintSlot)
    bpy.types.VIEW3D_PT_slots_projectpaint.remove(draw_display_slot_operator)

if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.paint.display_active_slot()

Blender 2.7x

enter image description here

bl_info = {
    "name": "Display active Slot",
    "description": "",
    "author": "brockmann",
    "version": (0, 0, 1),
    "blender": (2, 70, 0),
    "location": "Texture Paint > Tools Panel > Slots",
    "category": "Paint"
}

import bpy

class DisplayActivePaintSlot(bpy.types.Operator):
    '''Display selected paint slot in new window'''
    bl_label = "Display active Slot"
    bl_idname = "paint.display_active_slot"
    bl_options = {'REGISTER'}

    @classmethod
    def poll(self, context):
        return context.object.active_material.texture_paint_images

    def execute(self, context):
        if context.object.active_material.texture_paint_images:
            # Get the Image
            mat = bpy.context.object.active_material
            image = mat.texture_paint_images[mat.paint_active_slot]
            # Call user prefs window
            bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
            # Change area type
            area = context.window_manager.windows[-1].screen.areas[0]
            area.type = 'IMAGE_EDITOR'
            # Assign the Image
            context.area.spaces.active.image = image
        else:
            self.report({'INFO'}, "No active Slot")
        return {'FINISHED'}

def draw_display_slot_operator(self, context):
    if context.object.active_material.texture_paint_images:
        layout = self.layout
        row = layout.row(align=True)
        row.operator(DisplayActivePaintSlot.bl_idname, icon='IMAGE_COL')

def register():
    bpy.utils.register_class(DisplayActivePaintSlot)
    bpy.types.VIEW3D_PT_slots_projectpaint.prepend(draw_display_slot_operator)


def unregister():
    bpy.utils.unregister_class(DisplayActivePaintSlot)
    bpy.types.VIEW3D_PT_slots_projectpaint.remove(draw_display_slot_operator)

if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.paint.display_active_slot()
$\endgroup$
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.