1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
20 from bpy
.types
import Operator
21 from bpy
.props
import IntProperty
, BoolProperty
22 from sys
import platform
23 from bpy
.app
.handlers
import persistent
27 "name": "KTX RenderSlot",
28 "description": "Display/select renderslot in the render tab",
29 "author": "Roel Koster, @koelooptiemanna, irc:kostex",
31 "blender": (2, 80, 0),
32 "location": "Properties Editor > Render > Render",
34 "doc_url": "https://github.com/kostex/blenderscripts/",
35 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
39 nullpath
= '/nul' if platform
== 'win32' else '/dev/null'
46 class KTXRENDERSLOT_Prefs(bpy
.types
.AddonPreferences
):
49 advanced_mode
: bpy
.props
.BoolProperty(
51 description
="Gives the addon some advanced options",
54 def draw(self
, context
):
56 layout
.prop(self
, "advanced_mode")
59 class KTXRENDERSLOT_OT_Select(Operator
):
60 bl_label
= "Select Render Slot"
61 bl_idname
= "ktxrenderslot.select"
62 bl_description
= ("Select Render Slot\n"
63 "Note: Dot next to number means slot has image data\n"
66 number
: IntProperty()
68 def execute(self
, context
):
69 bpy
.data
.images
['Render Result'].render_slots
.active_index
= self
.number
75 def checkslots(scene
):
76 img
= bpy
.data
.images
['Render Result']
77 active
= img
.render_slots
.active_index
79 for i
in range(0,len(img
.render_slots
)):
80 img
.render_slots
.active_index
= i
82 img
.save_render(nullpath
)
87 if scene
.ktx_auto_advance_slot
:
89 if active
== len(img
.render_slots
):
90 img
.render_slots
.new()
93 scene
.ktx_occupied_render_slots
.data
= slots
94 img
.render_slots
.active_index
= active
97 def ui(self
, context
):
100 row
= layout
.row(align
=True)
101 row
.alignment
= 'LEFT'
102 img
= bpy
.data
.images
['Render Result']
103 active
= img
.render_slots
.active_index
104 if bpy
.context
.preferences
.addons
[__name__
].preferences
.advanced_mode
:
105 row
.prop(scn
, 'ktx_auto_advance_slot', text
='Auto Advance')
107 row
= layout
.row(align
=True)
108 row
.alignment
= 'EXPAND'
109 for i
in range(0,len(img
.render_slots
)):
110 is_active
= bool(i
== active
)
111 test_active
= bool(scn
.ktx_occupied_render_slots
.data
[i
] == '1')
112 icons
= "LAYER_ACTIVE" if test_active
else "BLANK1"
113 label
= "[{}]".format(str(i
+ 1)) if is_active
else str(i
+ 1)
114 row
.operator('ktxrenderslot.select', text
=label
, icon
=icons
).number
= i
118 row
= layout
.row(align
=True)
119 row
.alignment
= 'EXPAND'
123 KTXRENDERSLOT_OT_Select
,
129 from bpy
.utils
import register_class
131 bpy
.types
.RENDER_PT_context
.prepend(ui
)
132 bpy
.types
.Scene
.ktx_auto_advance_slot
= BoolProperty(default
=False, description
="Auto Advance to Next Slot after a Render")
133 bpy
.types
.Scene
.ktx_occupied_render_slots
= OccupiedSlots
135 bpy
.app
.handlers
.render_post
.append(checkslots
)
142 from bpy
.utils
import unregister_class
144 bpy
.types
.RENDER_PT_context
.remove(ui
)
145 del bpy
.types
.Scene
.ktx_occupied_render_slots
146 del bpy
.types
.Scene
.ktx_auto_advance_slot
148 bpy
.app
.handlers
.render_post
.remove(checkslots
)
151 unregister_class(cls
)
154 if __name__
== "__main__":