[Bf-blender-cvs] [a22167b9a2f] blender2.8: Fix/Updated Object API example.

Bastien Montagne noreply at git.blender.org
Mon Nov 5 20:42:25 CET 2018


Commit: a22167b9a2fec63b6da419f7a42075d4b722b950
Author: Bastien Montagne
Date:   Mon Nov 5 20:42:00 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBa22167b9a2fec63b6da419f7a42075d4b722b950

Fix/Updated Object API example.

Was still 2.7x code... ;)

===================================================================

M	doc/python_api/examples/bpy.types.Object.py

===================================================================

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



More information about the Bf-blender-cvs mailing list