2
$\begingroup$

So what I need is when Eyes Follow Cam is False then Head Follow cam and Influence is disabled(grayed out) and when Eyes Follow Cam is True then Head Follow cam and Influence is enabled

this is my panel

Here is the code for for the necessary parts:

import bpy 

from bpy.props import BoolProperty

bpy.types.Scene.EyesFollowCamera = BoolProperty(
    name="Eyes Follow Cam?",
        description="Makes the Eyes to follow the camera",
        default = False)
bpy.types.Scene.FollowCamera = BoolProperty(
    name="Head Follow Cam?",
        description="Makes the head and spine to follow the camera",
        default= False)

from bpy.props import FloatProperty

bpy.types.Scene.FollowInfluence = FloatProperty(
    name="Influence",
        description="Infuence of Head following eyes",step = 10,min=0, max=1,precision =3,
                default = 0.6)

class Blah_settings(bpy.types.Panel):
    bl_label = "Settings"
    bl_category = "IDK"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
   

    def draw(self, context):
        layout = self.layout
        sce = context.scene
        row = layout.row()
        row.prop(sce, "EyesFollowCamera", icon = "HIDE_OFF") 
        row.prop(sce, "FollowCamera", icon = "USER")
        row.prop(sce, "FollowInfluence")
      
classes = (Blah_settings, )


def register():
    for cls in classes:
        bpy.utils.register_class(cls)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()

Do I achieve it through a if statement? if so, how?

$\endgroup$
1

1 Answer 1

4
$\begingroup$

Assign any bool to UILayout.enabled (layout element): https://docs.blender.org/api/current/bpy.types.UILayout.html?highlight=uilayout#bpy.types.UILayout.enabled

When false, this (sub)layout is grayed out

enter image description here

Quick demo using the 'Use Nodes' property (bool) in the World Panel. If enabled the other element (can be anything) gets greyed out.

import bpy

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the World properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "WORLD_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "world"

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        row.operator("mesh.primitive_cube_add")
        
        # Layoutelement.enabled = any bool
        row.enabled = not context.world.use_nodes

def register():
    bpy.utils.register_class(HelloWorldPanel)
    
def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)

if __name__ == "__main__":
    register()

How do I get the opposite (negation) of a Boolean in Python?

$\endgroup$
1

Not the answer you're looking for? Browse other questions tagged .