diff --git a/scripts/modules/bpy_extras/node_shader_utils.py b/scripts/modules/bpy_extras/node_shader_utils.py index 0b17212b8ca..ce7646575d5 100644 --- a/scripts/modules/bpy_extras/node_shader_utils.py +++ b/scripts/modules/bpy_extras/node_shader_utils.py @@ -36,6 +36,22 @@ def values_clamp(val, minv, maxv): else: return max(minv, min(maxv, val)) +# TODO: Consider moving node_input_value_set/node_input_value_get into a common utility module if +# more usage merits doing so. If that is done, abstract out the validity check and make it usable +# for node outputs as well. See PR #119354 for details. +def node_input_value_set(node, input, value): + if node is None or input not in node.inputs: + return + + node.inputs[input].default_value = value + + +def node_input_value_get(node, input, default_value=None): + if node is None or input not in node.inputs: + return default_value + + return node.inputs[input].default_value + class ShaderWrapper(): """ @@ -798,13 +814,11 @@ class ShaderImageTextureWrapper(): node_mapping = property(node_mapping_get) def translation_get(self): - if self.node_mapping is None: - return Vector((0.0, 0.0, 0.0)) - return self.node_mapping.inputs["Location"].default_value + return node_input_value_get(self.node_mapping, "Location", Vector((0.0, 0.0, 0.0))) @_set_check def translation_set(self, translation): - self.node_mapping.inputs["Location"].default_value = translation + node_input_value_set(self.node_mapping, "Location", translation) translation = property(translation_get, translation_set)