1
$\begingroup$

I'm trying to create a custom operator to help me building armatures.

It should change behavior depending on a custom property defined in the operator class.

In addition, the "Adjust last operation" panel should only show the appropriate parameters depending on the selected behavior.

class MY_OT_BuildArmature(bpy.types.Operator):
    bl_idname = "wm.build_armature"
    bl_label = "Build Armature"
    bl_options = {'REGISTER', 'UNDO'}

    # Custom Properties 

    # Always used for armature creation
    orientation: EnumProperty(items=orientationTypes, name="Orientation", default="x+")
    
    # Property to control operator behavior
    use_list: BoolProperty(name="Use list", default=False)

    # Shown and used only when "use_list" is unchecked
    bone_count: IntProperty(name="Bone count", default=1)
    total_length: FloatProperty(name="Total length", default=1.0)

    # Shown and used only when "use_list" is checked
    bone_list: StringProperty(name="Bone list", default="1", options={"ANIMATABLE", "HIDDEN"})

    def execute(self, context):
        options: set = self.__annotations__["bone_list"].keywords["options"]

        if self.use_list:
            if not "HIDDEN" in options:
                options.add("HIDDEN")
            print(f"Use list: ON")
        else:
            if "HIDDEN" in options:
                options.remove("HIDDEN")
            print(f"Use list: OFF")

        # create armature code

        return {'FINISHED'}

Unfortunately, adding/removing "HIDDEN" has no effect on property visibility in the "Adjust last operation" panel.

If the "bone_list" property's "options" attribute is initially defined with "HIDDEN", the property is and stays hidden in the panel, whether or not the "use_list" property is checked. Same the opposite, initially defining without "HIDDEN" makes "bone_list" always visible.

So, it looks as if "HIDDEN" only works at initialization time, at least managed this way.

Is it possible to change the visibility of properties in the "Adjust last operation" panel and how?

$\endgroup$
2
  • $\begingroup$ Hello. AFAIK you can't adjust these properties at runtime. They're defined at register time. You can hack your way through modifying them with unregistering / reregistering the property but I wouldn't expect it to work with an operator $\endgroup$
    – Gorgious
    Commented Dec 10, 2023 at 16:19
  • $\begingroup$ What you want to do is use a custom draw method docs.blender.org/api/current/… $\endgroup$
    – Gorgious
    Commented Dec 10, 2023 at 16:21

0

You must log in to answer this question.

Browse other questions tagged .