I am using blender 3.0.0 and i have many shader trees on objects with undefined mix RGB nodes, is there a script or any other way to revers to the original nodes state on multiply objects?
$\begingroup$
$\endgroup$
9
-
$\begingroup$ Suggestion. Please include a screen capture of some relevant Blender UI. Please try to edit your writing to be more clear. $\endgroup$– atomicbezierslingerCommented Nov 4, 2022 at 18:30
-
$\begingroup$ The word [undefined] seems to be spelled in two different ways in your writing. The title seems incorrect. $\endgroup$– atomicbezierslingerCommented Nov 4, 2022 at 18:36
-
$\begingroup$ Are you trying to load files made in a much earlier version of blender (pre-2.83)? $\endgroup$– Christopher BennettCommented Nov 4, 2022 at 19:32
-
$\begingroup$ You're probably loading a .blend from a newer version of Blender. Easiest thing to do is just update your Blender. You could try writing a script to guess what the node should be from the input/output socket names but I don't think you can get what eg. the mode on Mix nodes should be. But really, just update Blender. $\endgroup$– scurestCommented Nov 5, 2022 at 18:14
-
$\begingroup$ @Christopher Bennett,Thanks, This is a file i have opened before in version 3.0 and never had this problem. I am not vey good at scripting. $\endgroup$– digitvisionsCommented Nov 5, 2022 at 18:35
|
Show 4 more comments
1 Answer
$\begingroup$
$\endgroup$
For another question I made a script that should theoretically be able to replace undefined Mix nodes in one click. It really works only on Mix nodes, typically as you get undefined ones when opening a file made on ≤3.4 into a Blender <3.4.
It will not recover the mix type nor input values. It will only preserve the old socket connections.
import bpy
for material in bpy.data.materials:
if not material.use_nodes:
continue
node_tree = material.node_tree
nodes = node_tree.nodes
fail_state = False
for node in nodes:
if node.name == "Mix":
try:
input_links = {}
output_link = None
if len(node.inputs) > 0 and node.inputs[0].is_linked: # Factor input
input_links[0] = node.inputs[0].links[0].from_socket
if len(node.inputs) > 6 and node.inputs[6].is_linked: # Color1 input
input_links[6] = node.inputs[6].links[0].from_socket
if len(node.inputs) > 7 and node.inputs[7].is_linked: # Color2 input
input_links[7] = node.inputs[7].links[0].from_socket
if len(node.outputs) > 0 and node.outputs[2].is_linked:
output_link = node.outputs[2].links[0].to_socket
mix_rgb_node = nodes.new(type="ShaderNodeMixRGB")
mix_rgb_node.location = node.location
mix_rgb_node.blend_type = 'MIX'
if 0 in input_links:
node_tree.links.new(input_links[0], mix_rgb_node.inputs[0]) # Factor input
if 6 in input_links:
node_tree.links.new(input_links[6], mix_rgb_node.inputs[1]) # Color1 input
if 7 in input_links:
node_tree.links.new(input_links[7], mix_rgb_node.inputs[2]) # Color2 input
# Reconnect the output link to the new MixRGB node's Color output
if output_link:
node_tree.links.new(mix_rgb_node.outputs[0], output_link)
nodes.remove(node)
except:
print(f"failed on material '{material.name}'")
fail_state = True
print(f"Replacement of 'Mix' nodes with 'MixRGB' nodes completed {'with errors' if fail_state else 'with no errors'}.")
Paste in text editor and run.