3
$\begingroup$

I've coded this enum property using this code:

class RuleCondition(PropertyGroup):
    data_type: EnumProperty(
        name="Condition Object Type",
        description="The type of data",
        items=[
            (
                RuleIDStrings.OBJECT,
                'Object',
                "The condition should be based on an object being present or not"
            ),
            (
                RuleIDStrings.MATERIAL,
                'Material',
                "The condition should be based on an object being present or not"
            )
        ],
    )
...

And it shows up like this in the interface:

enter image description here

Is there a way that I can make it non-animatable so that the little circle next to it allowing for keyframes doesn't show up? I've tried setting the is_animatable flag to False:

    data_type: EnumProperty(
        name="Condition Object Type",
        description="The type of data",
        items=[
            (
                RuleIDStrings.OBJECT,
                'Object',
                "The condition should be based on an object being present or not"
            ),
            (
                RuleIDStrings.MATERIAL,
                'Material',
                "The condition should be based on an object being present or not"
            )
        ],
        is_animatable=False
    )

But the EnumProperty can't register when I do that. It also doesn't allow me to use a colon instead of an equals sign (it says "positional argument follows keyword argument"). Any thoughts on how to make it so that this property isn't animatable?

UPDATE: When I pass an empty options parameter as shown below, I get the following error.

class RuleCondition(PropertyGroup):
    data_type: EnumProperty(
        name="Condition Object Type",
        description="The type of data",
        items=[
            (
                RuleIDStrings.OBJECT,
                'Object',
                "The condition should be based on an object being present or not"
            ),
            (
                RuleIDStrings.MATERIAL,
                'Material',
                "The condition should be based on an object being present or not"
            )
        ],
        options={}
    )
...

Error:

Traceback (most recent call last):
  File "/home/anson/.vscode/extensions/jacqueslucke.blender-development-0.0.17/pythonFiles/include/blender_vscode/operators/addon_update.py", line 27, in execute
    bpy.ops.preferences.addon_enable(module=self.module_name)
  File "/home/anson/Downloads/Software/blender-3.1.0-linux-x64/3.1/scripts/modules/bpy/ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Error: Traceback (most recent call last):
  File "/home/anson/Downloads/Software/blender-3.1.0-linux-x64/3.1/scripts/modules/addon_utils.py", line 387, in enable
    mod.register()
  File "/home/anson/.config/blender/3.1/scripts/addons/Brightaxe/__init__.py", line 112, in register
    _call_globals("register")
  File "/home/anson/.config/blender/3.1/scripts/addons/Brightaxe/__init__.py", line 108, in _call_globals
    getattr(m, attr_name)()
  File "/home/anson/.config/blender/3.1/scripts/addons/Brightaxe/properties/rules_properties.py", line 191, in register
    bpy.utils.register_class(class_to_register)
ValueError: bpy_struct "RuleCondition" registration error: 'data_type' EnumProperty could not register (see previous error)


Sending: {'type': 'enableFailure'}
$\endgroup$
0

1 Answer 1

4
$\begingroup$

TLDR; Add options=set() as a parameter when defining the EnumProperty to avoid passing the default {'ANIMATABLE'} value.

bpy.props.EnumProperty is a function that takes these arguments:

EnumProperty(items, name="", description="", default=None, options={'ANIMATABLE'}, override=set() .. function:: EnumProperty(items, name="", description="", default=None, options={'ANIMATABLE'}, override=set(), tags=set(), update=None, get=None, set=None)

You need to remove the attempt to set is_animatable directly and instead pass options={} as an argument. Unless you want to set any options from HIDDEN’, ‘SKIP_SAVE’, ‘ANIMATABLE’, ‘ENUM_FLAG’, ‘LIBRARY_EDITABLE, in which case you pass them in the options set.

    data_type: EnumProperty(
        name="Condition Object Type",
        description="The type of data",
        items=[
            (
                RuleIDStrings.OBJECT,
                'Object',
                "The condition should be based on an object being present or not"
            ),
            (
                RuleIDStrings.MATERIAL,
                'Material',
                "The condition should be based on an object being present or not"
            )
        ],
        options=set()
    )
$\endgroup$
8
  • $\begingroup$ Hi! Thanks so much for the answer! I tried adding it exactly as you show, but I receive the error "EnumProperty could not register" $\endgroup$ Jul 5 at 17:57
  • 1
    $\begingroup$ can you paste the entire error callback stack in your answer? $\endgroup$ Jul 5 at 17:59
  • $\begingroup$ Okay, I added the whole error stack! :) $\endgroup$ Jul 5 at 18:05
  • $\begingroup$ I think you have a problem with RuleIDStrings now, rather than with the animatable property, but I'd need to see the code where that's defined. $\endgroup$ Jul 5 at 19:31
  • $\begingroup$ Yeah, it could be except for that it registers fine before I add the options. Here's the code for that: ``` class RuleIDStrings(): """ This class acts as an Enum. """ OBJECT = "OBJECT" MATERIAL = "MATERIAL" IS = "IS" IS_NOT = "IS_NOT" SINGLE_MATERIAL = "SINGLE_MATERIAL" MATERIAL_GROUP = "MATERIAL_GROUP" EXCLUDE_OBJECT = "EXCLUDE_OBJECT" FORCE_INCLUDE_OBJECT = ... ``` $\endgroup$ Jul 5 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.