Last active
November 30, 2015 14:19
-
-
Save zeffii/e1cf3a62750475e1f289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import itertools | |
node_tree = bpy.data.materials['Material'].node_tree | |
node = node_tree.nodes['Mapping'] | |
def store_replace(node_tree, node): | |
props_to_copy = 'bl_idname name location height width'.split(' ') | |
reconnections = [] | |
mappings = itertools.chain.from_iterable([node.inputs, node.outputs]) | |
for i in (i for i in mappings if i.is_linked): | |
for L in i.links: | |
reconnections.append([L.from_socket.path_from_id(), L.to_socket.path_from_id()]) | |
props = {j: getattr(node, j) for j in props_to_copy} | |
new_node = node_tree.nodes.new(props['bl_idname']) | |
props_to_copy.pop(0) | |
for prop in props_to_copy: | |
setattr(new_node, prop, props[prop]) | |
nodes = node_tree.nodes | |
nodes.remove(node) | |
new_node.name = props['name'] | |
for str_from, str_to in reconnections: | |
node_tree.links.new(eval(str_from), eval(str_to)) | |
store_replace(node_tree, node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment