bc_search_scene

Übersicht: Python & Blender


Objectives

If the objects are created, in a second step further manipulations

Instructions

Tasks:
  1. What is possible with lists? If in doubt, have a look at Python basics: lists
  2. Create a script that executes the code from this station.
  3. Add a new object to the scene and run the script again.

Show all objects

In an new Blender file, in a scene some objects are placed by default. How to get a list of available objects is shown with the following script:

blender-basics/b-find-information/object-list.py (Source)

#!bpy
"""
Name: 'object-list.py'
Blender: 2.7x
Group: 'Discover'
Tooltip: 'Find objects in a scene'
"""

import bpy


def get_list_of_objects():
    """ Print list of objects in a scene """

    for i in bpy.data.objects:
        print(i)


if __name__ == '__main__':
    # call the new function
    get_list_of_objects()

The modul bpy.data contains as structure objects. From this you can get a list of objects of the context, the scene. A for loop is used to print all objects:

Result:

<bpy_struct, Object("Camera")>
<bpy_struct, Object("Cube")>
<bpy_struct, Object("Lamp")>
You can imagine, what sort of objects are available in the scene.
/all/label-windows.png

This is the output on a command line on windows.

/blender-basics/b-find-information/output-win.png

Comments