How to get Blender objects structure

Writing scripts in Blender we often need to know the full list of object properties to access them through the Blender API. Consider how we can get a list of available object methods and properties.

  1. “dir” command

The simplest way to get the complete structure of the object you need is to run the “dir” command in the Python Console window, specifying the object as the argument.

Let’s get the properties and methods of the Glossy BSDF node. Add it to the Node Editor, select it (make it active) and in the Python Console window execute the “dir” command, specifying the active node as the argument:

After executing the command, a list of properties and methods of the selected node will be displayed in the Python Console window:

dir command execution result

The “dir” command gives a complete structure of the object but does not show its current properties values.

  1. Saving the “rna” structure of the object to a file

After the “dir” command execution we can see that bl_rna and rna_type structures exist in the node object. This means that the rna-structure of this node can be stored in a file.

To do this, let’s write the following simple script:

This script creates a file named glossy_rna.xml in the blender project’s directory. Then, with the rna_xml module and the rna2xml command use, it saves the structure of the selected node (specified in the root_rna parameter) to this file.

The contents of the glossy_rna.xml file after script execution:

The structure of the node properties saved to file with their current values.

Combining this two methods of getting Blender objects structure, we can receive the complete information about their methods and properties with the current values.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments