1 # SPDX-License-Identifier: GPL-2.0-or-later
6 # A sorting func for collections (working in-place).
7 # XXX Not optimized at all…
8 # XXX If some items in the collection do not have the sortkey property, they are just ignored…
9 def collection_property_sort(collection
, sortkey
, start_idx
=0):
10 while start_idx
+ 1 < len(collection
):
11 while not hasattr(collection
[start_idx
], sortkey
):
13 if start_idx
+ 1 >= len(collection
):
16 min_prop
= collection
[start_idx
]
17 for i
, prop
in enumerate(collection
[start_idx
+ 1:]):
18 if not hasattr(prop
, sortkey
):
20 if getattr(prop
, sortkey
) < getattr(min_prop
, sortkey
):
22 min_idx
= i
+ start_idx
+ 1
23 collection
.move(min_idx
, start_idx
)
28 def scene_render_copy_settings_update():
29 """Prepare internal data for render_copy_settings (gathering all existing render settings, and scenes)."""
30 current_scene
= getattr(bpy
.context
, "scene", None)
31 if current_scene
is None:
33 cp_sett
= current_scene
.render_copy_settings
35 # Get all available render settings, and update accordingly affected_settings…
37 for prop
in current_scene
.render
.bl_rna
.properties
:
38 if prop
.identifier
in {'rna_type'}:
42 props
[prop
.identifier
] = prop
.name
44 for i
, sett
in enumerate(cp_sett
.affected_settings
):
45 if sett
.strid
not in props
:
46 cp_sett
.affected_settings
.remove(i
- corr
)
50 for strid
, name
in props
.items():
51 sett
= cp_sett
.affected_settings
.add()
52 sett
.name
= "{} [{}]".format(name
, strid
)
54 collection_property_sort(cp_sett
.affected_settings
, "name")
56 # Get all available scenes, and update accordingly allowed_scenes…
58 if cp_sett
.filter_scene
:
62 regex
= re
.compile(cp_sett
.filter_scene
)
63 except Exception as e
:
64 print("The filter-scene regex did not compile:\n (%s)." % str(e
))
68 print("Unable to import the re module, regex scene filtering will be disabled!")
70 for scene
in bpy
.data
.scenes
:
71 if scene
== current_scene
: # Exclude current scene!
73 # If a valid filtering regex, only keep scenes matching it.
75 if regex
.match(scene
.name
):
76 scenes
.add(scene
.name
)
78 scenes
.add(scene
.name
)
79 for i
, scene
in enumerate(cp_sett
.allowed_scenes
):
80 if scene
.name
not in scenes
:
81 cp_sett
.allowed_scenes
.remove(i
)
83 scenes
.remove(scene
.name
)
85 sett
= cp_sett
.allowed_scenes
.add()
87 collection_property_sort(cp_sett
.allowed_scenes
, "name")
90 from bpy
.props
import EnumProperty
93 class RenderCopySettingsOPPreset(bpy
.types
.Operator
):
94 """Apply some presets of render settings to copy to other scenes"""
95 bl_idname
= "scene.render_copy_settings_preset"
96 bl_label
= "Render: Copy Settings Preset"
97 bl_description
= "Apply or clear this preset of render settings"
99 bl_option
= {'REGISTER', 'UNDO'}
101 presets
: EnumProperty(items
=(p
.rna_enum
for p
in presets
.presets
),
103 options
={'ENUM_FLAG'})
106 def process_elements(settings
, elts
):
109 for sett
in settings
:
110 if sett
.strid
in elts
:
112 val
= val
and sett
.copy
117 def poll(cls
, context
):
118 return context
.scene
is not None
120 def execute(self
, context
):
121 cp_sett
= context
.scene
.render_copy_settings
122 for p
in presets
.presets
:
123 if p
.rna_enum
[0] in self
.presets
:
124 self
.process_elements(cp_sett
.affected_settings
, p
.elements
)
128 # Real interesting stuff…
130 def do_copy(context
, affected_settings
, allowed_scenes
):
131 # Stores render settings from current scene.
132 p
= {sett
: getattr(context
.scene
.render
, sett
)
133 for sett
in affected_settings
}
134 # put it in all other (valid) scenes’ render settings!
135 for scene
in bpy
.data
.scenes
:
136 # If scene not in allowed scenes, skip.
137 if scene
.name
not in allowed_scenes
:
139 # Propagate all affected settings.
140 for sett
, val
in p
.items():
141 setattr(scene
.render
, sett
, val
)
144 class RenderCopySettingsOPCopy(bpy
.types
.Operator
):
145 """Copy render settings from current scene to others"""
146 bl_idname
= "scene.render_copy_settings"
147 bl_label
= "Render: Copy Settings"
149 bl_option
= {'REGISTER', 'UNDO'}
152 def poll(cls
, context
):
153 return context
.scene
is not None
155 def execute(self
, context
):
157 cp_sett
= context
.scene
.render_copy_settings
158 affected_settings
= {sett
.strid
for sett
in cp_sett
.affected_settings
if sett
.copy
}
159 allowed_scenes
= {sce
.name
for sce
in cp_sett
.allowed_scenes
if sce
.allowed
}
160 do_copy(context
, affected_settings
=affected_settings
, allowed_scenes
=allowed_scenes
)
165 RenderCopySettingsOPPreset
,
166 RenderCopySettingsOPCopy
,