Advertisement
Guest User

Untitled

a guest
Feb 11th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.22 KB | Source Code | 0 0
  1. #Paste this shit into a text file in blender and run it
  2. import bpy
  3.  
  4. #Settings storage object, will live in the scene object
  5. class MaterialNodeSwitcherSettings(bpy.types.PropertyGroup):
  6.    
  7.     #Define functions for changing properties
  8.     def node_z_changed(self, context):
  9.         node_tree = bpy.data.objects["Cube"].data.materials[0].node_tree
  10.        
  11.         main_node = node_tree.nodes["MAIN"]
  12.         z_node = node_tree.nodes["NODE_Z"]
  13.         diffuse_node = node_tree.nodes["DIFFUSE"]
  14.        
  15.         if (self.node_z_adder == True):
  16.             node_tree.links.new(z_node.outputs[-1], diffuse_node.inputs["Color"])
  17.         else:
  18.             node_tree.links.new(main_node.outputs[-1], diffuse_node.inputs["Color"])
  19.    
  20.     def base_changed(self, context):
  21.         node_tree = bpy.data.objects["Cube"].data.materials[0].node_tree
  22.        
  23.         base_node = node_tree.nodes["BASE"]
  24.         base_a = node_tree.nodes["BASE_A"]
  25.         base_b = node_tree.nodes["BASE_B"]
  26.         base_c = node_tree.nodes["BASE_C"]
  27.        
  28.         if self.base_switcher == "Base_A":
  29.             node_tree.links.new(base_a.outputs[-1], base_node.inputs[-1])
  30.         elif self.base_switcher == "Base_B":
  31.             node_tree.links.new(base_b.outputs[-1], base_node.inputs[-1])
  32.         elif self.base_switcher == "Base_C":
  33.             node_tree.links.new(base_c.outputs[-1], base_node.inputs[-1])
  34.    
  35.     def sub_changed(self, context):
  36.         node_tree = bpy.data.objects["Cube"].data.materials[0].node_tree
  37.        
  38.         sub_node = node_tree.nodes["SUB"]
  39.         sub_a = node_tree.nodes["SUB_A"]
  40.         sub_b = node_tree.nodes["SUB_B"]
  41.         sub_c = node_tree.nodes["SUB_C"]
  42.        
  43.         if self.sub_switcher_one == "A":
  44.             node_tree.links.new(sub_a.outputs[-1], sub_node.inputs[-1])
  45.         elif self.sub_switcher_one == "B":
  46.             node_tree.links.new(sub_b.outputs[-1], sub_node.inputs[-1])
  47.         elif self.sub_switcher_one == "C":
  48.             node_tree.links.new(sub_c.outputs[-1], sub_node.inputs[-1])
  49.    
  50.     #Dropdowns
  51.     base_switcher : bpy.props.EnumProperty(name="Base", items=[ ("Base_A", "Base A", ""), ("Base_B", "Base B", ""), ("Base_C", "Base C", "") ], update=base_changed)
  52.     sub_switcher_one : bpy.props.EnumProperty(name="Sub_1", items=[("A", "A", ""), ("B", "B", ""), ("C", "C", "")], update=sub_changed)
  53.    
  54.     #Checkbox
  55.     node_z_adder : bpy.props.BoolProperty(name="Node_Z", default = False, update=node_z_changed)
  56.  
  57. #Panel class
  58. class MaterialNodeSwitcher(bpy.types.Panel):
  59.     bl_idname = "OBJECT_PT_node_switcher_thing"
  60.     bl_label = "Material node switcher thingie"
  61.     bl_space_type = "VIEW_3D"
  62.     bl_region_type = "UI"
  63.  
  64.     def draw(self, context):
  65.         #Draw a label
  66.         self.layout.label(text="xXx_cRaZy_CuMmEr_xXx_420 NODE SWITCHER")
  67.        
  68.         #Settings object
  69.         node_switcher_settings_object = bpy.context.scene.node_switcher_settings_object
  70.        
  71.         #This adds the settings from MaterialNodeSwitcherSettings: first argument is the settings object,
  72.                                                                 #second is the python name of the property,
  73.                                                                 #third is the text of the setting
  74.         self.layout.prop(node_switcher_settings_object, "base_switcher", text="Base:")
  75.         self.layout.prop(node_switcher_settings_object, "sub_switcher_one", text="Sub node:")
  76.         self.layout.prop(node_switcher_settings_object, "node_z_adder", text="Node Z Enable")
  77.  
  78. #List of the two classes for iteration
  79. classes = [MaterialNodeSwitcherSettings, MaterialNodeSwitcher]
  80.  
  81.  
  82. def register():
  83.     #This adds the new classes to memory
  84.     for new_class in classes:
  85.         bpy.utils.register_class(new_class)
  86.    
  87.     #And creates an instance of the settings class for storing settings in the Scene object
  88.     bpy.types.Scene.node_switcher_settings_object = bpy.props.PointerProperty(type=MaterialNodeSwitcherSettings)
  89.  
  90. #Undoes the above
  91. def unregister():
  92.     for new_class in classes:
  93.         bpy.utils.unregister_class(new_class)
  94.    
  95.     del bpy.types.Scene.node_switcher_settings_object
  96.  
  97. #Execution starts here when you run the script
  98. if __name__ == "__main__":
  99.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement