Page MenuHome

Python: active_shape_key is read-only so you can't easily set the active shape key using its name
Closed, ArchivedPublic

Description

System Information
Win8, GTX1070

Blender Version
Broken: 2.79

Short description of error

When trying to set the active shapekey by name using active_shape_key (from an object) I get an error: AttributeError: bpy_struct: attribute "active_shape_key" from "Object" is read-only

Setting the active shape key with an index using active_shape_key_index does work, so why can't you set the active shape key by name (string) using active_shape_key?

(If a string isn't desirable data.shape_keys.key_blocks[name] would be fine too)

Exact steps for others to reproduce the error
From default cube scene:

  1. Select the cube object and add two shape keys.
  2. Open the python console.
  3. Type C.selected_objects[0].active_shape_key = "Basis"
  4. You get the above error.
  5. Type C.selected_objects[0].active_shape_key_index = 0
  6. You successfully changed the active shape key.

Expected: both should have the same result.

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Unknown Status to Unknown Status.Nov 20 2018, 9:57 PM
Philipp Oeser (lichtwerk) claimed this task.

While there is always room for improvement, I wouldnt consider this a bug.

shape_keys.key_blocks.find("Basis") will give you the index (which you can use to set active_shape_key_index)

Thx for the report, but closing.