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 #####
24
# These operators are only defined because it seems impossible to directly
25
# edit properties from UI code…
28
# A sorting func for collections (working in-place).
29
# XXX Not optimized at all…
30
# XXX If some items in the collection do not have the sortkey property,
31
# they are just ignored…
32
def collection_property_sort(collection, sortkey, start_idx=0):
33
while start_idx + 1 < len(collection):
34
while not hasattr(collection[start_idx], sortkey):
36
if start_idx + 1 >= len(collection):
39
min_prop = collection[start_idx]
40
for i, prop in enumerate(collection[start_idx + 1:]):
41
if not hasattr(prop, sortkey):
43
if getattr(prop, sortkey) < getattr(min_prop, sortkey):
45
min_idx = i + start_idx + 1
46
collection.move(min_idx, start_idx)
51
class RenderCopySettingsPrepare(bpy.types.Operator):
53
Prepare internal data for render_copy_settings (gathering all existing
54
render settings, and scenes)
56
bl_idname = "scene.render_copy_settings_prepare"
57
bl_label = "Render: Copy Settings Prepare"
58
bl_option = {'REGISTER'}
61
def poll(cls, context):
62
return context.scene != None
64
def execute(self, context):
65
cp_sett = context.scene.render_copy_settings
67
# Get all available render settings, and update accordingly
70
for prop in context.scene.render.bl_rna.properties:
71
if prop.identifier in {'rna_type'}:
75
props[prop.identifier] = prop.name
77
for i, sett in enumerate(cp_sett.affected_settings):
78
if sett.strid not in props:
79
cp_sett.affected_settings.remove(i - corr)
83
for strid, name in props.items():
84
sett = cp_sett.affected_settings.add()
85
sett.name = "{} [{}]".format(name, strid)
87
collection_property_sort(cp_sett.affected_settings, "name")
89
# Get all available scenes, and update accordingly allowed_scenes…
91
if cp_sett.filter_scene:
95
regex = re.compile(cp_sett.filter_scene)
96
except Exception as e:
97
self.report('ERROR_INVALID_INPUT', "The filter-scene "
98
"regex did not compile:\n (%s)." % str(e))
102
self.report('WARNING', "Unable to import the re module. "
103
"Regex scene filtering will be disabled!")
105
for scene in bpy.data.scenes:
106
if scene == bpy.context.scene: # Exclude current scene!
108
# If a valid filtering regex, only keep scenes matching it.
110
if regex.match(scene.name):
111
scenes.add(scene.name)
113
scenes.add(scene.name)
114
for i, scene in enumerate(cp_sett.allowed_scenes):
115
if scene.name not in scenes:
116
cp_sett.allowed_scenes.remove(i)
118
scenes.remove(scene.name)
120
sett = cp_sett.allowed_scenes.add()
122
collection_property_sort(cp_sett.allowed_scenes, "name")
127
from bpy.props import EnumProperty
130
class RenderCopySettingsPreset(bpy.types.Operator):
131
'''Apply some presets of render settings to copy to other scenes'''
132
bl_idname = "scene.render_copy_settings_preset"
133
bl_label = "Render: Copy Settings Preset"
134
bl_description = "Apply or clear this preset of render settings"
136
bl_option = {'REGISTER', 'UNDO'}
138
presets = EnumProperty(items=(p.rna_enum for p in presets.presets),
140
options={"ENUM_FLAG"})
143
def process_elements(settings, elts):
146
for sett in settings:
147
if sett.strid in elts:
149
val = val and sett.copy
154
def poll(cls, context):
155
return context.scene != None
157
def execute(self, context):
158
cp_sett = context.scene.render_copy_settings
159
for p in presets.presets:
160
if p.rna_enum[0] in self.presets:
161
self.process_elements(cp_sett.affected_settings, p.elements)
165
# Real interesting stuff…
167
def do_copy(context, affected_settings, allowed_scenes):
168
# Stores render settings from current scene.
169
p = {sett: getattr(context.scene.render, sett)
170
for sett in affected_settings}
171
# put it in all other (valid) scenes’ render settings!
172
for scene in bpy.data.scenes:
173
# If scene not in allowed scenes, skip.
174
if scene.name not in allowed_scenes:
176
# Propagate all affected settings.
177
for sett, val in p.items():
178
setattr(scene.render, sett, val)
181
class RenderCopySettings(bpy.types.Operator):
182
'''Copy render settings from current scene to others'''
183
bl_idname = "scene.render_copy_settings"
184
bl_label = "Render: Copy Settings"
186
bl_option = {'REGISTER', 'UNDO'}
189
def poll(cls, context):
190
return context.scene != None
192
def execute(self, context):
194
cp_sett = context.scene.render_copy_settings
195
affected_settings = {sett.strid for sett in cp_sett.affected_settings
197
allowed_scenes = {sce.name for sce in cp_sett.allowed_scenes
199
do_copy(context, affected_settings=affected_settings,
200
allowed_scenes=allowed_scenes)
204
if __name__ == "__main__":
205
bpy.ops.scene.render_copy_settings()