I have a custom panel with a bunch of things doing various stuff. They're all linked to custom properties that are linked to other things, it was just easier for me to understand, I'm a beginner python programer!. The issue is, when I change the values from the custom property itself, it changes the values that they're all linked to and everything works perfectly. But the problem is that when I use the custom panel, it changes the custom property values, but thats it. For example, in the linked code below, the iSight Camera Indicator is linked to an emission node. When I use the custom property, it changes the emission from 0 to 1, but when I use the panel, it doesn't...
Here is my code:
import bpy
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty)
def update_after_enum(self, context):
print ("place holder")
D = bpy.data
if colors == 'Gold':
D.objects['Macbook'].material_slots[0].material = D.materials['Gold']
D.objects['Macbook'].material_slots[9].material = D.materials['Gold Apple Logo']
elif colors == 'Silver':
D.objects['Macbook'].material_slots[0].material = D.materials['Silver']
D.objects['Macbook'].material_slots[9].material = D.materials['Silver']
elif colors == 'Space Grey':
D.objects['Macbook'].material_slots[0].material = D.materials['Space Grey']
D.objects['Macbook'].material_slots[9].material = D.materials['Space Grey Apple Logo']
def common_update(self, context, origin):
obj = bpy.data.objects.get("Macbook")
if not obj:
return
if origin == 'isight_camera_indicator':
obj["00_iSight Camera Indicator"] = getattr(self, origin)
node_tree = bpy.data.materials['iSight Camera Indicator'].node_tree
node = node_tree.nodes["Emission"]
if getattr(self, origin):
emission_value = 5.0
else:
emission_value = 0.0
nodes["Emission"].inputs[1].default_value = emission_value
elif origin == 'dirt_and_dust':
obj["01_Dirt and Dust"] = getattr(self, origin)
elif origin == 'menubar_and_dock':
obj["02_Menubar and Dock"] = getattr(self, origin)
elif origin == 'screen_rotation':
obj["03_Screen Rotation"] = getattr(self, origin)
class IgnitProperties(bpy.types.PropertyGroup):
isight_camera_indicator = BoolProperty(
name = "iSight Camera Indicator",
description = "Toggles the iSight Camera Indicator ON and OFF",
default = False,
update = lambda self, context: common_update(self, context, 'isight_camera_indicator')
)
dirt_and_dust = BoolProperty(
name = "Dirt and Dust",
description = "Toggles the Dirt and Dust ON and OFF",
default = False,
update = lambda self, context: common_update(self, context, 'dirt_and_dust')
)
menubar_and_dock = BoolProperty(
name = "Menubar and Dock",
description = "Toggles the Menubar and Dock ON and OFF",
default = False,
update = lambda self, context: common_update(self, context, 'menubar_and_dock')
)
screen_rotation = FloatProperty(
name = "Screen Rotation",
description = "Rotates the screen",
default = 0.0,
min = 0.0,
max = 1.0,
update = lambda self, context: common_update(self, context, 'screen_rotation')
)
#MacBook Colors
colors = EnumProperty(
name = "MacBook Colors",
description = "Changes the color of the MacBook",
items = [
("Silver", "Silver", "Silver"),
("Gold", "Gold", "Gold"),
("Space Grey", "Space Grey", "Space Grey")
],
update = update_after_enum
)
class IGLayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "MacBook Controller"
bl_idname = "object_mode.macbook_controller"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
layout.label(text = "Main Features:")
scene = context.scene
split = layout.split()
scene = context.scene
camera = scene.camera.data
# First column
col = split.column()
col.prop(scene.ignit_panel, "isight_camera_indicator")
col.prop(scene.ignit_panel, "dirt_and_dust")
# Second Column
col = split.column()
col.prop(scene.ignit_panel, "menubar_and_dock")
col.prop(scene.ignit_panel, "screen_rotation")
# MacBook Colors
layout.label(text = "MacBook Color:")
row = layout.row(align=True)
row.prop(scene.ignit_panel, "colors", expand = True)
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.ignit_panel = bpy.props.PointerProperty(type=IgnitProperties)
def unregister():
bpy.utils.unregister__module(__name__)
del bpy.types.Scene.ignit_panel
if __name__ == "__main__":
register()
nodes["Emission"].inputs[1].default_value = emission_value
is wrong.nodes
reference doesn't exist. (tidying up comments this comment should be here, not under my code) $\endgroup$