-3
$\begingroup$

Where can I learn the data structure within Blender and how to access it in a script?

(So that I will have some idea what exists and where my scripted data should be stored to be consistent with good design.)

I see little point in asking a specific question because that won't tell me how to figure out the next one for myself. I need to understand the system to be able to solve future problems.

$\endgroup$
3
  • 5
    $\begingroup$ This question seems a bit unfocused - Best identify a problem your trying to solve and ask questions based on that. - Where it is stored - is also vague. Where on disk? in memory? in the undo stack? $\endgroup$
    – ideasman42
    Commented Dec 7, 2015 at 13:49
  • $\begingroup$ I find a good way to explore the possibilities and contents of a data block is to go into blender's command line, type in ( in this example ) bpy.[whatever module you want to explore] and press ctrl+space. This will give you all the modules that specific block contains, allowing you to have some semblance of guidance when looking through the official documentation. $\endgroup$
    – MaVCArt
    Commented Dec 7, 2015 at 16:37
  • $\begingroup$ TheBeachdancer, You are welcome and encouraged to ask specific questions, after a while what we think you mean and what you really mean will intersect. You might best learn how the data structure works by reading some of the many addons in /scripts/addons especially those by ideasman42 (campbell barton) and bart crouch. mont29. $\endgroup$
    – zeffii
    Commented Dec 8, 2015 at 13:24

2 Answers 2

5
$\begingroup$

Any API can be menacing before you get familiar with it, especially in a truly complex program like Blender.

The documentation is accessible and fairly good, but you need to know what you are looking for.

And once you do get familiar with it, you'll see clear patterns of behavior everywhere. For instance, the "filepath" property is very common not just for VSE strips, but also for loaded images (For instance bpy.data.images[0].image.filepath) and many other objects.

To jump start your familiarity with the API, read the docs, check out the Code Snippets cookbook, inspect the code of some of the bundled addons that come with Blender, go over a few nice blogs like Blender Python, Blender Sushi, Small Blender Things. The learning curve is steep, but one you get over the initial hurdles you'll progress fast.

Now regarding your specific question about how to store globally accessible properties, with a little patience you can find a great answer right here on this Blender Stack Exchange website (also check the related questions in the right side panel).

$\endgroup$
-1
$\begingroup$

Internal global data in Blender is stored in a structure made of datablocks.

It is a branching hierarchy. For example:

    bpy.types.Object(ID) #which has sub categories such as..

        active_shape_key
        active_material

Or:

    context.scene.render.filepath

(That is where the render output filepath is stored. It can be accessed, but not assigned, in a user's script.)

In a script it is possible to add one's own data block to this structure by linking it in this general way

    bpy.types.XXXXXXXX.newDataAddress = bpy.props.TTTTTTT(parameters)

in which XXXXXX is an existing valid Blender datablock, TTTTTTT is the reserved word for the type of the data and 'parameters' are the permitted and required definitions. For example:

    bpy.types.scene.new_data_name = 
    bpy.props.StringProperty(name = "TotalNotes" )

which can then be accessed through

    bpy.data.scene["TotalNotes"]

Commonly, user data gets tagged onto the end of a passed argument called context, normally in the form:

    self.context.userdata

--------------------------small print warnings --------- The above is based on a what I have learnt since asking the question so it is not reliable.

$\endgroup$

You must log in to answer this question.

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