Hey there,
I know this has probably been asked over & over already, but I just couldn’t quite wrap my head around any of what the search spit out.
You may skip the lengthy explanation in the next paragraph & look right at the code below, if you like:).
So I’m writing (well, tryin’ 2) a little script needed 4 a rig I’m working on. For now I’m just tryin’ 2 get a simple prototype working.
It’s meant 2 draw a panel with a checkbox & a (non-dynamic) popup-menu, giving 3 choices. I’ve figured out how to do this on the UI-side of things, so I have my BoolProperty and my checkbox in the panel as well as my EnumProperty and the corresponding popup-menu.
I’ve also duct-taped together an operator which is meant 2 hide ceartain objects if the checkbox gets checked/the Bool==True.
What I think I need now is an update function, such that toggling the checkbox will immediately run the operator and hide/reveal the objects.
Here’s what I have (forgive me if it’s messy):
import bpy
from bpy.props import *
Ob = [bpy.data.objects["Cube"], bpy.data.objects["Plane"]]
#def update_EyeLeftOptions(self, context):
# print(self,context)
def initSceneProperties(sce):
bpy.types.Scene.EyeLeftClosed=BoolProperty(
name="Eye Closed",
description="Closes Eye",
default = False)
# update=)
# sce['EyeLeftClosed'] = False
bpy.types.Scene.EyeLeftOptions=EnumProperty(
items=[('1', 'Default Behaviour', 'Deforms Upper Boundary Of Eyeballs'),
('2', 'Eyelid Visible', 'Shows Upper Eyelid'),
('3', 'Angry Shape', 'Static Angry Eyeshape')],
name="")
# update=update_EyeLeftOptions)
sce['EyeLeftOptions'] = 1
initSceneProperties(bpy.context.scene)
def hide_meshes(hide):
for ob in Ob:
if ob.type!='MESH':
continue
ob.hide=hide
ob.hide_render=hide
class hideOperator(bpy.types.Operator):
'''Tooltip'''
bl_idname="object.hide_operator"
bl_label="Hide"
if bpy.context.scene.EyeLeftClosed:
hide_meshes(True)
else:
hide_meshes(False)
bpy.utils.register_class(hideOperator)
class showFaceExtrasEyes(bpy.types.Panel):
bl_label = "Face Extras: Eyes"
#bl_idname = "myPanelID"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self,context):
layout = self.layout
sce=context.scene
layout.label("Eye Left:")
layout.prop(sce, 'EyeLeftClosed')
layout.prop(sce, 'EyeLeftOptions')
bpy.utils.register_class(showFaceExtrasEyes)
# Registration
bpy.utils.register_module(__name__)
Any help would be appreciated.
greetings,
Kologe