diff options
Diffstat (limited to 'doc/python_api/examples/bpy.types.Object.py')
-rw-r--r-- | doc/python_api/examples/bpy.types.Object.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/doc/python_api/examples/bpy.types.Object.py b/doc/python_api/examples/bpy.types.Object.py index 90c50bcfad7..f141ac7ce0f 100644 --- a/doc/python_api/examples/bpy.types.Object.py +++ b/doc/python_api/examples/bpy.types.Object.py @@ -3,26 +3,27 @@ Basic Object Operations Example +++++++++++++++++++++++++++++++ This script demonstrates basic operations on object like creating new -object, placing it into scene, selecting it and making it active. +object, placing it into a view layer, selecting it and making it active. """ import bpy from mathutils import Matrix -scene = bpy.context.scene +view_layer = bpy.context.view_layer -# Create new lamp datablock -lamp_data = bpy.data.lamps.new(name="New Lamp", type='POINT') +# Create new light datablock. +light_data = bpy.data.lights.new(name="New Light", type='POINT') -# Create new object with our lamp datablock -lamp_object = bpy.data.objects.new(name="New Lamp", object_data=lamp_data) +# Create new object with our light datablock. +light_object = bpy.data.objects.new(name="New Light", object_data=light_data) -# Link lamp object to the scene so it'll appear in this scene -scene.objects.link(lamp_object) +# Link light object to the active collection of current view layer, +# so that it'll appear in the current scene. +view_layer.collections.active.collection.objects.link(light_object) -# Place lamp to a specified location -lamp_object.location = (5.0, 5.0, 5.0) +# Place light to a specified location. +light_object.location = (5.0, 5.0, 5.0) -# And finally select it make active -lamp_object.select = True -scene.objects.active = lamp_object +# And finally select it and make it active. +light_object.select_set('SELECT') +view_layer.objects.active = light_object |