Hi,
I was wondering if someone could explain how to use boolean tick boxes in python, is it something along the lines of:
if bpy.types.Scene.flipx_bool == True:
do this
else:
do that
Thanks
Tom
Hi,
I was wondering if someone could explain how to use boolean tick boxes in python, is it something along the lines of:
if bpy.types.Scene.flipx_bool == True:
do this
else:
do that
Thanks
Tom
That wont work i dont think.
bpy.types.Scene.flip = bpy.props.BoolProperty(default=True)
gives each scene in the file a flip boolean property with a default of True. Needs to be set to appear.
You can set it like
scene = bpy.context.scene
scene.flip = False
#toggle the flip
scene.flip = not scene.flip
#use it in an if
if scene.flip:
print("do a flip")
Looking at the type value in the console will give this
>>> bpy.types.Scene.flip
(<built-in function BoolProperty>, {'default': True, 'attr': 'flip'})
>>> C.scene.flip
False
Hi,
Okay, so I have this code (inside a bigger program with the default True):
scene = bpy.context.scene
scene.flipx_bool = False
#toggle the flip
scene.flipx_bool = not scene.flipx_bool
#use it in an if
if scene.flipx_bool:
print("do a flip")
else:
print("Bye")
But when I run the operator it’s inside, it uses True everytime. However, if I comment the “scene.flipx_bool = not scene.flipx_bool” line, it always uses false.
Thanks
Tom
That makes sense. You’re setting it to False in line 2, then toggling it in line 4. If you don’t toggle it it is False, if you do then it is true
Are you trying to do something like this:
Create the ‘scene’ property:
def register():
...
bpy.types.Scene.Verbose = bpy.props.BoolProperty(
name="Verbose",
default=False)
Display it in a panel:
class MyRenderPanel(bpy.types.Panel):
bl_label = "My Render Panel"
bl_idname = "OBJECT_PT_MyRender"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "render"
def draw(self, context):
layout = self.layout
scene = context.scene
...
row = layout.row()
row.prop(scene, "Verbose")
Use the property in code:
if context.scene.Verbose:
do something
...
btw, it was batFINGER that helped me get this working.
Thanks, thats solved it, although I had to use “if bpy.context.scene.Verbose:”
Thanks
Tom