forked from bartvdbraak/blender
Fix/Updated Object API example.
Was still 2.7x code... ;)
This commit is contained in:
parent
5ae853d20a
commit
a22167b9a2
@ -3,26 +3,27 @@ Basic Object Operations Example
|
|||||||
+++++++++++++++++++++++++++++++
|
+++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
This script demonstrates basic operations on object like creating new
|
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
|
import bpy
|
||||||
from mathutils import Matrix
|
from mathutils import Matrix
|
||||||
|
|
||||||
scene = bpy.context.scene
|
view_layer = bpy.context.view_layer
|
||||||
|
|
||||||
# Create new lamp datablock
|
# Create new light datablock.
|
||||||
lamp_data = bpy.data.lamps.new(name="New Lamp", type='POINT')
|
light_data = bpy.data.lights.new(name="New Light", type='POINT')
|
||||||
|
|
||||||
# Create new object with our lamp datablock
|
# Create new object with our light datablock.
|
||||||
lamp_object = bpy.data.objects.new(name="New Lamp", object_data=lamp_data)
|
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
|
# Link light object to the active collection of current view layer,
|
||||||
scene.objects.link(lamp_object)
|
# so that it'll appear in the current scene.
|
||||||
|
view_layer.collections.active.collection.objects.link(light_object)
|
||||||
|
|
||||||
# Place lamp to a specified location
|
# Place light to a specified location.
|
||||||
lamp_object.location = (5.0, 5.0, 5.0)
|
light_object.location = (5.0, 5.0, 5.0)
|
||||||
|
|
||||||
# And finally select it make active
|
# And finally select it and make it active.
|
||||||
lamp_object.select = True
|
light_object.select_set('SELECT')
|
||||||
scene.objects.active = lamp_object
|
view_layer.objects.active = light_object
|
||||||
|
Loading…
Reference in New Issue
Block a user