I am trying to set the Lamp type using Python scripting. I've got the Lamp object:
Lamp = bpy.data.objects["Lamp"]
Lamp.type seems read-only. How can I set it without creating a new lamp?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Confusion between object and its data
Blender has many object types, 'LAMP' is one of them. It is set by the data type on creation and is read only.
>>> D.objects['Lamp'] bpy.data.objects['Lamp'] >>> D.objects['Lamp'].type 'LAMP' >>> D.objects['Lamp'].type = 'LAMP' Traceback (most recent call last): File "/usr/lib/python3.6/code.py", line 91, in runcode exec(code, self.locals) File "<blender_console>", line 1, in <module> AttributeError: bpy_struct: attribute "type" from "Object" is read-only
'LAMP' type object (
bpy.data.objects) has a lamp (
bpy.data.lamps) object as its data. Just like a
'MESH' object has a mesh (
bpy.data.meshes) The type of lamp can be set on the data part.
>>> D.objects['Lamp'].data bpy.data.lamps['Lamp'] >>> lamp = D.objects['Lamp'].data >>> lamp.type 'SPOT' >>> lamp.type = 'HEMI' >>> lamp.type 'HEMI'