How to display library overrides as checkboxes?

Custom properties can’t be displayed as checkboxes. I usually handle this by dynamically defining new API properties, like this:

setattr(bpy.types.Object, "myprop", BoolProperty(default=False))
setattr(ob, "myprop", False)
ob["myprop"] = False

and add the following line to the draw function:

self.layout.prop(ob, "myprop")

This works nicely in the blend file where the property was defined. However, when the collection is linked into another file and I make a library override, the checkbox is greyed out and says: Disabled: Can't edit this property from an override data block.


The first idea was to make the property overridable, i.e. to change the first line to:

setattr(bpy.types.Object, "myprop", BoolProperty(default=False, override={'LIBRARY_OVERRIDABLE'}))

and/or adding the line

ob.property_overridable_library_set('["myprop"]', True)

Alas, neither changes anything; the checkboxes are still greyed out in the linked file. Finally, setting the api property as overridable, like this

ob.property_overridable_library_set("myprop", True)

results in the error message

TypeError: Object.property_overridable_library_set("myprop") not found

What sort of works is to display the custom property rather than the api property, i.e. changing the draw function to:

self.layout.prop(ob, '["myprop"]')

But then the boolean properties are displayed as integers.


Is there any way to override boolean properties and still display them as checkboxes?

It turns out that the following works.

setattr(bpy.types.Object, "myprop", BoolProperty(default=value))
setattr(ob, "myprop", value)
ob[prop] = value
ob.property_overridable_library_set('["myprop"]', True)

Note that the argument override={'LIBRARY_OVERRIDABLE'} is missing from the BoolProperty. If present, the next setattr will cause an error. To display checkboxes, draw the property with this line:

self.layout.prop(ob, "myprop")

1 Like