1 # SPDX-License-Identifier: GPL-2.0-or-later
8 # A sorting func for collections (working in-place).
9 # XXX Not optimized at all…
10 # XXX If some items in the collection do not have the sortkey property, they are just ignored…
11 def collection_property_sort(collection
, sortkey
, start_idx
=0):
12 while start_idx
+ 1 < len(collection
):
13 while not hasattr(collection
[start_idx
], sortkey
):
15 if start_idx
+ 1 >= len(collection
):
18 min_prop
= collection
[start_idx
]
19 for i
, prop
in enumerate(collection
[start_idx
+ 1:]):
20 if not hasattr(prop
, sortkey
):
22 if getattr(prop
, sortkey
) < getattr(min_prop
, sortkey
):
24 min_idx
= i
+ start_idx
+ 1
25 collection
.move(min_idx
, start_idx
)
30 def scene_render_copy_settings_update():
31 """Prepare internal data for render_copy_settings (gathering all existing render settings, and scenes)."""
32 current_scene
= getattr(bpy
.context
, "scene", None)
33 if current_scene
is None:
35 cp_sett
= current_scene
.render_copy_settings
37 # Get all available render settings, and update accordingly affected_settings…
39 for prop
in current_scene
.render
.bl_rna
.properties
:
40 if prop
.identifier
in {'rna_type'}:
44 props
[prop
.identifier
] = prop
.name
46 for i
, sett
in enumerate(cp_sett
.affected_settings
):
47 if sett
.strid
not in props
:
48 cp_sett
.affected_settings
.remove(i
- corr
)
52 for strid
, name
in props
.items():
53 sett
= cp_sett
.affected_settings
.add()
54 sett
.name
= "{} [{}]".format(name
, strid
)
56 collection_property_sort(cp_sett
.affected_settings
, "name")
58 # Get all available scenes, and update accordingly allowed_scenes…
60 if cp_sett
.filter_scene
:
64 regex
= re
.compile(cp_sett
.filter_scene
)
65 except Exception as e
:
66 print("The filter-scene regex did not compile:\n (%s)." % str(e
))
70 print("Unable to import the re module, regex scene filtering will be disabled!")
72 for scene
in bpy
.data
.scenes
:
73 if scene
== current_scene
: # Exclude current scene!
75 # If a valid filtering regex, only keep scenes matching it.
77 if regex
.match(scene
.name
):
78 scenes
.add(scene
.name
)
80 scenes
.add(scene
.name
)
81 for i
, scene
in enumerate(cp_sett
.allowed_scenes
):
82 if scene
.name
not in scenes
:
83 cp_sett
.allowed_scenes
.remove(i
)
85 scenes
.remove(scene
.name
)
87 sett
= cp_sett
.allowed_scenes
.add()
89 collection_property_sort(cp_sett
.allowed_scenes
, "name")
92 from bpy
.props
import EnumProperty
95 class RenderCopySettingsOPPreset(bpy
.types
.Operator
):
96 """Apply some presets of render settings to copy to other scenes"""
97 bl_idname
= "scene.render_copy_settings_preset"
98 bl_label
= "Render: Copy Settings Preset"
99 bl_description
= "Apply or clear this preset of render settings"
101 bl_option
= {'REGISTER', 'UNDO'}
103 presets
: EnumProperty(items
=(p
.rna_enum
for p
in presets
.presets
),
105 options
={'ENUM_FLAG'})
108 def process_elements(settings
, elts
):
111 for sett
in settings
:
112 if sett
.strid
in elts
:
114 val
= val
and sett
.copy
119 def poll(cls
, context
):
120 return context
.scene
is not None
122 def execute(self
, context
):
123 cp_sett
= context
.scene
.render_copy_settings
124 for p
in presets
.presets
:
125 if p
.rna_enum
[0] in self
.presets
:
126 self
.process_elements(cp_sett
.affected_settings
, p
.elements
)
130 # Real interesting stuff…
132 def do_copy(context
, affected_settings
, allowed_scenes
):
133 # Stores render settings from current scene.
134 p
= {sett
: getattr(context
.scene
.render
, sett
)
135 for sett
in affected_settings
}
136 # put it in all other (valid) scenes’ render settings!
137 for scene
in bpy
.data
.scenes
:
138 # If scene not in allowed scenes, skip.
139 if scene
.name
not in allowed_scenes
:
141 # Propagate all affected settings.
142 for sett
, val
in p
.items():
143 setattr(scene
.render
, sett
, val
)
146 class RenderCopySettingsOPCopy(bpy
.types
.Operator
):
147 """Copy render settings from current scene to others"""
148 bl_idname
= "scene.render_copy_settings"
149 bl_label
= "Render: Copy Settings"
151 bl_option
= {'REGISTER', 'UNDO'}
154 def poll(cls
, context
):
155 return context
.scene
is not None
157 def execute(self
, context
):
159 cp_sett
= context
.scene
.render_copy_settings
160 affected_settings
= {sett
.strid
for sett
in cp_sett
.affected_settings
if sett
.copy
}
161 allowed_scenes
= {sce
.name
for sce
in cp_sett
.allowed_scenes
if sce
.allowed
}
162 do_copy(context
, affected_settings
=affected_settings
, allowed_scenes
=allowed_scenes
)
167 RenderCopySettingsOPPreset
,
168 RenderCopySettingsOPCopy
,