1
$\begingroup$

I found bpy.types.SunLight(Light), but I don't know how to use it.

Can someone explain please?

I need to change some of the Sun's settings (strength/specular/angle) with python

Not a duplicate of how to GET a lamp, as this is a completely different question

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Even this is a different question, you should post your first attempt (some code) at least. $\endgroup$
    – brockmann
    Sep 19, 2019 at 21:27

1 Answer 1

3
$\begingroup$

You can access the lights either through bpy.data.lights where all lights of the .blend file can be found or bpy.context.scene.objects which contains all objects in the current scene, including lights. For the latter you need to access .data for the light settings.

If you have a light called Sun in the current scene you could use either one of the approaches to modify the properties, as shown in the following example.

import bpy
import math

sun = bpy.data.lights["Sun"]
#sun = bpy.context.scene.objects["Sun"].data

sun.color = (1.0, 0.0, 0.0)
sun.energy = 5.0
sun.specular_factor = 0.5
sun.angle = math.pi * 10.0 / 180.0  # In radians
$\endgroup$
5
  • $\begingroup$ Thanks, it works! @rjg $\endgroup$
    – cxnt
    Sep 19, 2019 at 14:09
  • $\begingroup$ One little question, how do I rotate sun? $\endgroup$
    – cxnt
    Sep 19, 2019 at 14:12
  • $\begingroup$ I've tried it says AttributeError: 'SunLight' object has no attribute 'rotation_euler' $\endgroup$
    – cxnt
    Sep 19, 2019 at 14:27
  • 1
    $\begingroup$ Right. Use bpy.context.scene.objects["Sun"] to get the object and set the rotation with bpy.context.scene.objects["Sun"].rotation_euler $\endgroup$
    – Robert Gützkow
    Sep 19, 2019 at 14:32
  • $\begingroup$ Yup, thanks a lot!!! @rjg $\endgroup$
    – cxnt
    Sep 19, 2019 at 14:40

Not the answer you're looking for? Browse other questions tagged .