I am trying to set the Lamp type using Python scripting. I've got the Lamp object:

Lamp = bpy.data.objects["Lamp"]

But Lamp.type seems read-only. How can I set it without creating a new lamp?

  • 1
    $\begingroup$ I'll assume you're using blender 2.7x get the lamp from bpy.data.lamps not objects then be sure to set it with caps('HEMI', 'AREA', 'SPOT', etc). Also i wouldn't recommend using Lamp as a name since it is a named structure. $\endgroup$ – Ratt Feb 10 at 21:37

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']

>>> D.objects['Lamp'].type

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

A '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

>>> lamp = D.objects['Lamp'].data
>>> lamp.type

>>> lamp.type = 'HEMI'
>>> lamp.type

It is not read only. Try:

Lamp = bpy.data.objects["Lamp"]
Lamp.location = (0, -2, 3.7)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.