Page MenuHome

Custom Properties: officially support int and float arrays in the UI.

Authored by Alexander Gavrilov (angavrilov) on Aug 10 2019, 3:35 PM.



In some rare cases it is convenient to store a short array value
as a custom property, e.g. a vector or color. For example, it may
be helpful when importing/exporting certain formats that support
custom or nonstandard attributes on objects.

The custom property storage already can handle arrays in order to
support properties defined via python. The only thing missing is
UI support (and some bugs), and this patch fixes that:

  • Allow editing short array properties via Custom Properties panel.
  • Fix a UI layout sizing bug triggered by the previous item.
  • Fix a dependency graph bug with drivers using such properties.
  • Make RNA_*_get_default_array code robust in case of size mismatch.
  • Support custom default values for array properties, allowing both an array and a scalar value.

Diff Detail

rB Blender

Event Timeline

Campbell Barton (campbellbarton) requested changes to this revision.Aug 12 2019, 11:07 AM

Generally seems fine, comments inline


Is there any reason to convert this to a list to check it's length?

Checking the length directly should work.


Spaces around [ ... ] aren't pep8 compliant.


Extending the last value seems odd (we don't do this elsewhere).

We could just zero anything not included in the default.

In general this function seems a bit more involved then it needs to be, we could just memcpy the default array clamped by each maxumum, and memset the remainder (if it's needed).

This revision now requires changes to proceed.Aug 12 2019, 11:07 AM

Python code cleanup, simplified default handling.

Alexander Gavrilov (angavrilov) marked 3 inline comments as done.Aug 12 2019, 6:08 PM
Alexander Gavrilov (angavrilov) added inline comments.

I didn't check what operations IDPropertyArray supports itself, since I saw other code converting it. However that code was doing it to convert into a nice string.


The function also supports using a simple scalar to initialize all elements of the array to the same value, and the filling remainder part reuses the same loop.

Re extending the value, I thought that the last value is a more reasonable estimate of a good default than just 0. However, the size mismatch case is mainly a failsafe in case the data provided by the user (or python code) is inconsistent, so I decided the code might as well be simpler. For a truly 'arbitrarily' sized array, the appropriate tool here is to use the single scalar method.

Campbell Barton (campbellbarton) requested changes to this revision.Aug 13 2019, 3:12 PM
Campbell Barton (campbellbarton) added inline comments.

Double quotes for all except enum literals.


The default may be set, the else case should delete the default.

This looks like an issue with the description too (unrelated to this patch).


On first read this made me think of an array-of-int16's, could call use_compact_array_ui or show_array_ui


This test doesn't seem correct, since the default may have been set previously, the default should be deleted in an else branch in this case.

    prop_ui.pop("default", None)
This revision now requires changes to proceed.Aug 13 2019, 3:12 PM
Alexander Gavrilov (angavrilov) marked 2 inline comments as done.Aug 13 2019, 4:03 PM
Alexander Gavrilov (angavrilov) added inline comments.

Changed to isinstance.


This is a 'create' function, so it wipes everything in rna_ui just above here so that the result is completely predictable.


This was pretty much a duplicate of the code rna_idprop_ui_prop_default_set, so I changed to using it.

This revision is now accepted and ready to land.Aug 13 2019, 4:07 PM