2
$\begingroup$

I'd like to control these bools there via Python but I can't quite figure out how.

both ""

If I try something like this code, "min", "max", "soft_min" and "soft_max" work fine and update their values but "is_overridable_library" and "use_soft_limits" do not.

import bpy
obj = bpy.context.object
obj["_RNA_UI"] = {"prop":{"min":0,"max":1,"soft_min":0,"soft_max":1,"is_overridable_library":1,"use_soft_limits":1}}

Thank you very much!

$\endgroup$
6
  • $\begingroup$ I'm trying to create overridable custom properties in a script. I'm able to set name, description, values, min and max but I cannot figure out how to make those properties overridable so that once linked the object's collection in another file I can play with those custom properties. I tried both 0/1 and False/True but it's not working anyway. Thanks! $\endgroup$ Mar 8, 2020 at 11:19
  • $\begingroup$ Alright, now I understand what you're trying to do. $\endgroup$
    – Robert Gützkow
    Mar 8, 2020 at 11:35
  • $\begingroup$ While it may be possible to edit this through _RNA_UI, I'd avoid using a private variable from an undocumented part of the API and instead update it through bpy.ops.wm.properties_edit(). $\endgroup$
    – Robert Gützkow
    Mar 8, 2020 at 11:52
  • $\begingroup$ I tried that but it gives me a RuntimeError. Specifically: RuntimeError: Error: Direct execution not supported. I found another thread regarding this issue, the same that gave me the idea of using "_RNA_UI". blender.stackexchange.com/questions/143975/… $\endgroup$ Mar 8, 2020 at 12:08
  • $\begingroup$ You're right. However setting is_overridable_library through _RNA_UI doesn't seem to work either, when modifying an existing property. I'll have to look at the source code as see what's going on. Sorry for causing any confusion. $\endgroup$
    – Robert Gützkow
    Mar 8, 2020 at 12:38

2 Answers 2

6
$\begingroup$

The value behind is_overridable_library can be set through the method property_overridable_library_set() of an object. The following example demonstrates how to set a custom property named "prop" to be overridable.

import bpy


obj = bpy.context.object
obj.property_overridable_library_set('["prop"]', True)

The use_soft_limits is dynamically evaluated and it's not necessary to set it when using the Python API. If the soft_max or soft_min are different than the max or min, it will automatically show as enabled.

Calling bpy.ops.wm.properties_edit() results in an error message, because it expects that self._last_prop is set. This only happens in the invoke() function, not when calling execute() directly. Therefore the execution context has to be set by passing INVOKE_DEFAULT.

bpy.ops.wm.properties_edit("INVOKE_DEFAULT", data_path="object", property="prop", value="1.0", default="1.0", min=0, max=1, use_soft_limits=False, is_overridable_library=True, soft_min=0, soft_max=1, description="", subtype="NONE")

The downside of this is that the UI popup appears and has to be confirmed. Therefore the operator cannot be used without user interaction.

$\endgroup$
1
  • $\begingroup$ Thank you very much! $\endgroup$ Mar 8, 2020 at 13:36
1
$\begingroup$

To add to this, getting whether a property is library overridable or not is also not obvious:

bpy.context.object.is_property_overridable_library('["prop"]')

$\endgroup$

You must log in to answer this question.

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