9
$\begingroup$

I need to store additional information in a .blend file, that occurs only once per file. So, attaching it to, for example, bpy.types.Scene doesn't help.

Since bpy.data is an instance of bpy.types.BlendData, I tried attaching properties to bpy.types.BlendData. This failed:

>>> bpy.types.BlendData.testProp = bpy.props.StringProperty()
>>> bpy.data.testProp
(<built-in function StringProperty>, {})

Here, bpy.data.testProp is not a string, but some tuple, So it looks like registering properties on bpy.types.BlendData is not supported, like it is for bpy.types.Object:

>>> bpy.types.Object.testProp = bpy.props.StringProperty()
>>> bpy.data.objects['Camera'].testProp
''

Is it somehow possible to attach properties to bpy.types.BlendData?

Are there other ways to register global data in a .blend file?

$\endgroup$
9
$\begingroup$

Short answer: no, you cannot store per-file custom data.

A .blend file is basically just a collection of ID data blocks. There is no customizable data instance for "the file". All custom data must be associated to one of the ID blocks (or possibly eligible subdata that supports custom props, like bones or nodes).

Depending on what you actually want to do there are a number of other options:

  • You could make a dummy ID block (e.g. Text) to which you add custom data
  • Addon preferences can store custom properties for persistent settings of addon scripts
  • Scene data blocks can be a viable option, they are a sort of "root node" in most cases

It really depends on the actual use case.

$\endgroup$
  • $\begingroup$ Neither the second nor the third tips are viable in my case, since the data must be stored in the .blend file and there might be multiple scenes. The first tip is a bit of a hack, but that's fine with me :) $\endgroup$ – Fab Apr 3 '14 at 14:04

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.