Is there any chance to get index of custom property ?

enter image description here

Thanks to batFINGER I found that you can acces custom property by:

import bpy
bpy.context.active_object.keys()[i] # i is index

but if I have array in the property i dont know how to find specific value. I used:


for third value of the array but it doesnt work.

  • 2
    $\begingroup$ Not sure how useful a custom property index is? Are they in same order as the ob.keys() list? $\endgroup$ – batFINGER Mar 8 '18 at 14:48
  • $\begingroup$ You cant manually use a name of property and you can add and remove property and searching the values only by for loop. I do everythink little bit responsive. $\endgroup$ – MRL Mar 8 '18 at 15:05
  • $\begingroup$ Yes but i have 36-360 properties, sometimes they are used and sometimes they are not - it depends on source data. So I would like to get the data by index, because I know the order. $\endgroup$ – MRL Mar 8 '18 at 15:11
  • $\begingroup$ View source on the custom props panel rna_prop_ui.py. Can emulate the way that is ordered . $\endgroup$ – batFINGER Mar 8 '18 at 15:12
  • 1
    $\begingroup$ If you have the nn_ naming convention, perhaps use that with list comp. {p : ob[p] for p in ob.keys() if p.name.startswith("%2d_" % index)} $\endgroup$ – batFINGER Mar 8 '18 at 15:37

Lets dissect what your code does:

key = bpy.context.active_object.keys()[2]
# key contains the name '02_back'

char = key[2]
# gets the third character which is '_'

# which throws an error as key '_' does not exist

It should be


Let's dissect this

key = bpy.context.active_object.keys()[2]
# key contains the name '02_back'

prop = bpy.context.active_object.get(key)
# gets the property with the name '02_back'

value = prop[2]
# gets the third item of the property `1.2`
  • $\begingroup$ The order of the props in the UI is sorted and filtered (doesn't list _RNA_UI key for instance that will have index after the UI prop was created). Quite often cycles sits in index 0. IMO relying on keys()[2] to be the one in position 2 is a slippery slope. $\endgroup$ – batFINGER Mar 9 '18 at 13:56
  • 1
    $\begingroup$ Agree I just repeated what the question was using. $\endgroup$ – J. Bakker Mar 9 '18 at 15:45
  • $\begingroup$ Yes, you are right batFinger, but I am glad that there are explain the basic system - that was the goal. RNA_UI and cycles property can by easily skip by your previous code. $\endgroup$ – MRL Mar 10 '18 at 20:14

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.