Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19.  
  20. import bpy
  21. import itertools
  22.  
  23. bl_info = {
  24. "name": "Reset A Cycles Node",
  25. "author": "zeffii, poor",
  26. "version": (0, 1),
  27. "blender": (2, 7, 6),
  28. "location": "",
  29. "description": "",
  30. "warning": "",
  31. "wiki_url": "",
  32. "tracker_url": "",
  33. "category": "Node"
  34. }
  35.  
  36.  
  37. def store_replace(node):
  38. node_tree = node.id_data
  39. props_to_copy = 'bl_idname name location height width'.split(' ')
  40.  
  41. reconnections = []
  42. mappings = itertools.chain.from_iterable([node.inputs, node.outputs])
  43. for i in (i for i in mappings if i.is_linked):
  44. for L in i.links:
  45. reconnections.append([L.from_socket.path_from_id(), L.to_socket.path_from_id()])
  46.  
  47. props = {j: getattr(node, j) for j in props_to_copy}
  48.  
  49. new_node = node_tree.nodes.new(props['bl_idname'])
  50. props_to_copy.pop(0)
  51.  
  52. for prop in props_to_copy:
  53. setattr(new_node, prop, props[prop])
  54.  
  55. nodes = node_tree.nodes
  56. nodes.remove(node)
  57. new_node.name = props['name']
  58.  
  59. for str_from, str_to in reconnections:
  60. node_tree.links.new(eval(str_from), eval(str_to))
  61.  
  62. node_tree.nodes.active = new_node
  63.  
  64.  
  65. def main(operator, context):
  66. space = context.space_data
  67. node_active = context.active_node
  68. node_selected = context.selected_nodes
  69.  
  70. if not (len(node_selected) == 1) and node_active:
  71. operator.report({'ERROR'}, "1 node must be selected")
  72. return
  73.  
  74. # now we have an active node.
  75. store_replace(node_active)
  76.  
  77.  
  78. class NodeResetOperator(bpy.types.Operator):
  79. """Tooltip"""
  80. bl_idname = "node.delete_and_rebuild"
  81. bl_label = "Reset Node (keep connections)"
  82.  
  83. @classmethod
  84. def poll(cls, context):
  85. space = context.space_data
  86. return space.type == 'NODE_EDITOR'
  87.  
  88. def execute(self, context):
  89. main(self, context)
  90. return {'FINISHED'}
  91.  
  92.  
  93. def draw_reset_node(self, context):
  94. row = self.layout.row()
  95. row.operator("node.delete_and_rebuild", icon="FILE_REFRESH")
  96.  
  97.  
  98. def register():
  99. bpy.utils.register_module(__name__)
  100. bpy.types.NODE_PT_active_node_generic.prepend(draw_reset_node)
  101. bpy.types.NODE_MT_node.prepend(draw_reset_node)
  102.  
  103.  
  104. def unregister():
  105. bpy.types.NODE_PT_active_node_generic.remove(draw_reset_node)
  106. bpy.types.NODE_MT_node.remove(draw_reset_node)
  107. bpy.utils.unregister_module(__name__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement