0
$\begingroup$

I need to fix up animation on a character mesh every time I resync a linked armature, because the related mesh shape_keys animation gets deleted. Manually I have to navigate to the mesh object, expand, find a track(?) called "Key.005", Add a Track and then find and assign my an action named "Key.005Action" to this NlaTrack (yes, really!).

I want to script around this ... predicament.

How do I script to find the key below the desired mesh name, select and add a track here?

enter image description here

Once I find and select the "Key.005" item/row I could then:

bpy.ops.nla.tracks_add(above_selected=False)
bpy.ops.nla.actionclip_add(action='Key.005Action')

Unfortunately this answer nor this doesn't get me there as nla_tracks for the main object are empty, as will be for the Key.005 sub-whatever.

I include a simple file with a cube with shape keys. How do I assign the KeyAction to "Key.001" with a python script? (but remember that the action on "Key" of "Cube" was deleted upon a resync!)

enter image description here

$\endgroup$
6
  • $\begingroup$ Don't quite follow, but the tracks for a shapekey are at obj.data.shape_keys.animation_data.nla_tracks. $\endgroup$
    – scurest
    Mar 28, 2023 at 17:41
  • $\begingroup$ @scurest -- obj.data.shape_keys.animation_data.nla_tracks[:] returns [] if there is no existing NlaTrack there, as happens when I resync the armature. So I need to find the "Key.005" row somehow, to then tracks_add(). $\endgroup$
    – james_t
    Mar 28, 2023 at 19:16
  • $\begingroup$ You can create a new track/strip directly without using an op, see eg this A. $\endgroup$
    – scurest
    Mar 28, 2023 at 19:32
  • $\begingroup$ @scurest -- I need to find the node "Key.005" that lives inside some hierarchy. You are not helping me find this node to operate on. I had already visited that link: obj.animation_data.nla_tracks.new() will put a new track in the wrong place, and assigning the Key.005Action there will throw an error. Could not add action 'Key.005Action' as it cannot be used relative to ID-blocks of type 'OBGenesis8Male.Shape.001' $\endgroup$
    – james_t
    Mar 28, 2023 at 19:41
  • $\begingroup$ I already said the tracks are obj.data.shape_keys.animation_data.nla_tracks so you would do obj.data.shape_keys.animation_data.nla_tracks.new(). $\endgroup$
    – scurest
    Mar 28, 2023 at 19:47

1 Answer 1

1
$\begingroup$
import bpy
action = bpy.data.actions["KeyAction"]
ob = bpy.data.objects["Cube.001"]
track = ob.data.shape_keys.animation_data.nla_tracks.new()
track.strips.new(action.name, 1, action)
$\endgroup$
1
  • $\begingroup$ Gracias, mon ami; to mix languages! $\endgroup$
    – james_t
    Mar 28, 2023 at 20:16

You must log in to answer this question.

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