Fix/Updated Object API example.

Was still 2.7x code... ;)
This commit is contained in:
Bastien Montagne 2018-11-05 20:42:00 +01:00
parent 5ae853d20a
commit a22167b9a2
1 changed files with 14 additions and 13 deletions

View File

@ -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