743322492b4254bd0c89899312025e4abb2b317a
[blender.git] / doc / python_api / examples / bpy.types.Object.py
1 """
2 Basic Object Operations Example
3 +++++++++++++++++++++++++++++++
4
5 This script demonstrates basic operations on object like creating new
6 object, placing it into a view layer, selecting it and making it active.
7 """
8
9 import bpy
10 from mathutils import Matrix
11
12 view_layer = bpy.context.view_layer
13
14 # Create new light datablock.
15 light_data = bpy.data.lights.new(name="New Light", type='POINT')
16
17 # Create new object with our light datablock.
18 light_object = bpy.data.objects.new(name="New Light", object_data=light_data)
19
20 # Link light object to the active collection of current view layer,
21 # so that it'll appear in the current scene.
22 view_layer.active_layer_collection.collection.objects.link(light_object)
23
24 # Place light to a specified location.
25 light_object.location = (5.0, 5.0, 5.0)
26
27 # And finally select it and make it active.
28 light_object.select_set(True)
29 view_layer.objects.active = light_object