13

How can I access a custom property of an object from python, the suggestion Blender gives me if I pass the mouse over the custom properties named "prop",

bpy.data.objects["Cube"].["prop"] 

get me this output in the console

>>> bpy.data.objects["Cube"].["prop"]
  File "<blender_console>", line 1
    bpy.data.objects["Cube"].["prop"]
                             ^
SyntaxError: invalid syntax
darius
  • 327
  • 2
  • 4
  • 9

2 Answers2

17

You just need to remove the dot, so the correct invocation is:

bpy.data.objects["Cube"]["prop"]

Python's subscription syntax doesn't use dot character.

Note: In Python terminology this is known as getitem rather then getattr access.

ideasman42
  • 47,387
  • 10
  • 141
  • 223
Adhi
  • 14,310
  • 1
  • 55
  • 62
0

It is possible to store datablocks in "custom properties". I just did an experiment:

m = bpy.data.movieclips.load("bigbuckbunny.mp4")
bpy.context.scene["cliche free video"] = m

You can see it in the Scene tab of the Properties panel at the bottom. It appears to be preserved across a save/load cycle.

I'm not sure how many different datablocks support custom properties, but you might find one that is a better match than Scene (like an Object, or a Material).

I think you could even store an array of movieclips in there.

Mutant Bob
  • 9,243
  • 2
  • 29
  • 55