Page MenuHome

When add "shape key" by script, active_shape_key return "None" but active_shape_key_index return 0
Closed, ResolvedPublic

Description

System Information
Operating system:
Graphics card:

Blender Version
Broken: 2.83 2.90

Short description of error
When generate shape key by script, even though the mesh have shape keys,
bpy return None for Ob.active_shape_key

Exact steps for others to reproduce the error
1 Load cube in new blender scene
2 Open python console editor, with select cube, input these code in console

ob = C.object
skey = ob.shape_key_add()
skey.name = "Basis"
print(ob.active_shape_key_index)

I can get "0" as active_shape_key_index value.
then input,

print(ob.active_shape_key.name)

it expect to return "Basis" which I set for the new shape key.but return

Traceback (most recent call last):

File "<blender_console>", line 1, in <module>

AttributeError: 'NoneType' object has no attribute 'name'

Then
print(active_shape_key)

return "None"

Though I can avoid this problem, but it is somehow strange behavor I think.
if Active_shape_key is none, I suppose it never return active_shape_key_index .
And basically if there is shape key, in mesh, I expect, threre should be active_shape_key.

This behavor cause error for some add on script, which add shape keys. or we can not see it in blender UI. (always one shape key show high light as active, then I can not set shape keys as "no active shape key) from blender UI.