Tricky way
Well, actually you can do it without scripting:
Add a new item in key map in window section, operator is wm.context_toggle
, attribute is scene.world.node_tree.nodes["Mix Shader"].inputs[0].default_value
, where "Mix Shader"
is the node name. Your node might have different name, check that do you have in here:
Operator way
The more proper way is to do the operator. This is the script that I made from simple operator preset:
import bpy
def main(context):
node_tree = context.scene.world.node_tree
input = node_tree.nodes["Mix Shader"].inputs[0]
input.default_value = 0 if input.default_value == 1 else 1
class ToggleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "wm.toggle_update"
bl_label = "Toggle Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(ToggleOperator)
def unregister():
bpy.utils.unregister_class(ToggleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.wm.toggle_update()
Your node might have different name (not "Mix Shader"
), check that do you have in here:
This script creates operator. You can set it like this in keymaps:
To make this script works across files, you can save it as .py file and install as an addon. In this case, you should add addon info block.