[Solved] Property updating another property in C?

How can I do something like this in C? I’m not seeing any example while browsing code. Not sure if it’s even possible.

    def enum_2_update(self, context):
        if self.toggle and self.enum_1:
            self.enum_2 = self.enum_1

When toggle is not selected.

When toggle is selected or toggle selected and enum 1 changed, it updates enum 2 to match enum 1.

Python code

import bpy

class SimpleOperator(bpy.types.Operator):                
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}

    def enum_2_update(self, context):
        if self.toggle and self.enum_1:
            self.enum_2 = self.enum_1
    enum_1 = bpy.props.EnumProperty(
                    name="Enum 1",
                    items = (("OPTION_1","Option 1",""),
                        ("OPTION_2","Option 2",""),
                        ("OPTION_3","Option 3",""),
                        ("OPTION_4","Option 4","")),                                                                                                                   
                    default = "OPTION_2",
                    update = enum_2_update)
    enum_2 = bpy.props.EnumProperty(
                    name="Enum 2",
                    items = (("OPTION_1","Option 1",""),
                        ("OPTION_2","Option 2",""),
                        ("OPTION_3","Option 3",""),
                        ("OPTION_4","Option 4","")),                                                                                                                   
                    default = "OPTION_2")

    toggle = bpy.props.BoolProperty(
                    name = "Toggle",
                    description = "Toggle",
                    default = False,
                    update = enum_2_update)
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width=300)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        layout.use_property_decorate = False

        row = layout.row(align=False)        
        row.prop(self, "toggle", text="Toggle")
        row = layout.row(align=False)        
        row.prop(self, "enum_1", text="")
        row.prop(self, "enum_2", text="")
    def execute(self, context):
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":

I guess you’re just looking for RNA_enum_set(), check RNA_access.h for all others.

Been trying something like this. Not sure how you access “self” and operator “properties” in C.

static void enum_2_update(bContext *C, wmOperator *op)
  /* get properties? */
  PropertyRNA *enum_1 = RNA_struct_find_property(op->ptr, "enum_1");
  PropertyRNA *toggle = RNA_struct_find_property(op->ptr, "toggle");

  /* get enum 1 property value? */
  int enum_1_val = RNA_enum_get(op->ptr, "enum_1");

  /* check for toggle and enum 1? */
  if (toggle && enum_1) {
    /* set enum 2 value to enum 1 value? */
    RNA_enum_set(op->ptr, "enum_2", enum_1_val);

also, getting this in console

ERROR (rna.define): C:\blender-git\blender\source\blender\makesrna\intern\rna_define.c:2921 RNA_def_property_update: only during preprocessing.

I tried adding the following inside image_new_draw(), it seems to work.
(New Image popup, Image Editor.)

if (RNA_boolean_get(&ptr, "alpha")){
  RNA_enum_set(&ptr, "generated_type", IMA_GENTYPE_GRID);
1 Like

Whenever possible, don’t update a property based on another property, but rather design your properties so that there is no need. It often leads to confusing UI and odd behavior in Python scripting.