Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Paste this shit into a text file in blender and run it
- import bpy
- #Settings storage object, will live in the scene object
- class MaterialNodeSwitcherSettings(bpy.types.PropertyGroup):
- #Define functions for changing properties
- def node_z_changed(self, context):
- node_tree = bpy.data.objects["Cube"].data.materials[0].node_tree
- main_node = node_tree.nodes["MAIN"]
- z_node = node_tree.nodes["NODE_Z"]
- diffuse_node = node_tree.nodes["DIFFUSE"]
- if (self.node_z_adder == True):
- node_tree.links.new(z_node.outputs[-1], diffuse_node.inputs["Color"])
- else:
- node_tree.links.new(main_node.outputs[-1], diffuse_node.inputs["Color"])
- def base_changed(self, context):
- node_tree = bpy.data.objects["Cube"].data.materials[0].node_tree
- base_node = node_tree.nodes["BASE"]
- base_a = node_tree.nodes["BASE_A"]
- base_b = node_tree.nodes["BASE_B"]
- base_c = node_tree.nodes["BASE_C"]
- if self.base_switcher == "Base_A":
- node_tree.links.new(base_a.outputs[-1], base_node.inputs[-1])
- elif self.base_switcher == "Base_B":
- node_tree.links.new(base_b.outputs[-1], base_node.inputs[-1])
- elif self.base_switcher == "Base_C":
- node_tree.links.new(base_c.outputs[-1], base_node.inputs[-1])
- def sub_changed(self, context):
- node_tree = bpy.data.objects["Cube"].data.materials[0].node_tree
- sub_node = node_tree.nodes["SUB"]
- sub_a = node_tree.nodes["SUB_A"]
- sub_b = node_tree.nodes["SUB_B"]
- sub_c = node_tree.nodes["SUB_C"]
- if self.sub_switcher_one == "A":
- node_tree.links.new(sub_a.outputs[-1], sub_node.inputs[-1])
- elif self.sub_switcher_one == "B":
- node_tree.links.new(sub_b.outputs[-1], sub_node.inputs[-1])
- elif self.sub_switcher_one == "C":
- node_tree.links.new(sub_c.outputs[-1], sub_node.inputs[-1])
- #Dropdowns
- base_switcher : bpy.props.EnumProperty(name="Base", items=[ ("Base_A", "Base A", ""), ("Base_B", "Base B", ""), ("Base_C", "Base C", "") ], update=base_changed)
- sub_switcher_one : bpy.props.EnumProperty(name="Sub_1", items=[("A", "A", ""), ("B", "B", ""), ("C", "C", "")], update=sub_changed)
- #Checkbox
- node_z_adder : bpy.props.BoolProperty(name="Node_Z", default = False, update=node_z_changed)
- #Panel class
- class MaterialNodeSwitcher(bpy.types.Panel):
- bl_idname = "OBJECT_PT_node_switcher_thing"
- bl_label = "Material node switcher thingie"
- bl_space_type = "VIEW_3D"
- bl_region_type = "UI"
- def draw(self, context):
- #Draw a label
- self.layout.label(text="xXx_cRaZy_CuMmEr_xXx_420 NODE SWITCHER")
- #Settings object
- node_switcher_settings_object = bpy.context.scene.node_switcher_settings_object
- #This adds the settings from MaterialNodeSwitcherSettings: first argument is the settings object,
- #second is the python name of the property,
- #third is the text of the setting
- self.layout.prop(node_switcher_settings_object, "base_switcher", text="Base:")
- self.layout.prop(node_switcher_settings_object, "sub_switcher_one", text="Sub node:")
- self.layout.prop(node_switcher_settings_object, "node_z_adder", text="Node Z Enable")
- #List of the two classes for iteration
- classes = [MaterialNodeSwitcherSettings, MaterialNodeSwitcher]
- def register():
- #This adds the new classes to memory
- for new_class in classes:
- bpy.utils.register_class(new_class)
- #And creates an instance of the settings class for storing settings in the Scene object
- bpy.types.Scene.node_switcher_settings_object = bpy.props.PointerProperty(type=MaterialNodeSwitcherSettings)
- #Undoes the above
- def unregister():
- for new_class in classes:
- bpy.utils.unregister_class(new_class)
- del bpy.types.Scene.node_switcher_settings_object
- #Execution starts here when you run the script
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement