0
$\begingroup$

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?

$\endgroup$
1
  • 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, 2019 at 21:37

2 Answers 2

1
$\begingroup$

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

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
bpy.data.lamps['Lamp']

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

>>> lamp.type = 'HEMI'
>>> lamp.type
'HEMI'
$\endgroup$
0
$\begingroup$

It is not read only. Try:

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

You must log in to answer this question.

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