13
$\begingroup$

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
$\endgroup$

2 Answers 2

17
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

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