2
$\begingroup$

In relation to 'List' of Properties in NLA Strip. see that part for details...

  1. How can I get the list (and its custom properties) saved into a "specific" NLA Strip, so the item(s) in the list update to whatever NLA Strip is active (and so it can be accessed 'per-Strip').

Thank you for any help you can give.

$\endgroup$
2
  • $\begingroup$ sorry it took so long to get back to you with an answer for part 2. $\endgroup$ Jan 12, 2022 at 1:31
  • $\begingroup$ It's cool, it took me this long to figure out Pt1. ☺ $\endgroup$
    – Candle
    Jan 13, 2022 at 21:28

1 Answer 1

3
+150
$\begingroup$

As it turns out, for reasons I should have known, you can't do precisely what you want. Perhaps this will work well enough in its place.

The problem is that in order to add properties to a class, that class has to inherit from one of three classes and NlaStrip, the class you would like to add properties to does not inherit from any of them.

However, every NlaStrip includes an Action and Action does inherit from ID, one of the necessary classes.

This won't be an exact substitute because a single Action can appear in multiple NlaStrips.

As you will recall from my answer to part 1 I attached custom properties to the Scene data type but warned that

Scene might not be the correct type

It's not. When you attach a property to a type, you get one instance for each thing of that type. Since you want a unique instance for each NLA Strip, the property should be attached to the NLA strip. But as I said above we can't do that so we'll attach it to each Action, and access the Actions through the NLA strip.

Revisiting the code from part 1, this means that the setup should now look something like this:

import bpy

from bpy.props import StringProperty, FloatProperty
from bpy.types import PropertyGroup, Action

class myPropertyGroup(PropertyGroup):
    """Group of properties representing an item in the list."""
    name: StringProperty(
           name="Name",
           description="A name for this item",
           default="Untitled")
    custom_prop_1: FloatProperty(
           name="Custom Property 1",
           description="a floating point property",
           default=0.0)
    custom_prop_2: StringProperty(
            name="Custom Property 2",
            description="a string property",
            default="")
            
bpy.utils.register_class(myPropertyGroup)

Action.myStuff = bpy.props.PointerProperty(type=myPropertyGroup)

Now you only need to find the NLA Strip you're interested in and then you can access the properties using code like

strip.action.myStuff.name = "Inigo Montoya"

As to how to find the strip, there are several ways. Here's a brute force method that walks through all of the strips and notices the active ones:

object = bpy.context.active_object
animation_data = object.animation_data
nla_tracks = animation_data.nla_tracks

strips = []
for track in nla_tracks:
    for strip in track.strips:
        if strip.active:
            strips.append(strip)

for strip in strips:
    print(f"{strip.name} {strip.action.name} {strip.action.myStuff.name}")
$\endgroup$
4
  • 1
    $\begingroup$ I was wrong before; I actually do want it saved to an action, so this should work perfectly (once I figure it out). I think I tried doing this already, but suppose I missed something. $\endgroup$
    – Candle
    Jan 16, 2022 at 0:23
  • $\begingroup$ Worked beautifully. I'd tried using the Action in the past but didn't know how to use the for loops to access that information. Thank you so much for the help and for supporting those with less experience than you. $\endgroup$
    – Candle
    Jan 19, 2022 at 7:12
  • $\begingroup$ @Smail You are very welcome. I really appreciate the thought behind your bounty; but it is too generous. I don't need the reputation but keeping it would help you. I know bounties are supposed to be non-refundable, but maybe you can ask an admin if there's a way to cancel it. Clicking 'accept' was all I would every ask for. $\endgroup$ Jan 19, 2022 at 15:55
  • 1
    $\begingroup$ You helped me through the early days of figuring out how BPY works; helped me move towards independence as a programmer. Keep it, it'll do more good for you than for me. I'm not really sure what it's even for anyway. Heh, besides, it's not like I get nothing from it. You'll remember my name should the time come again. -- Seriously though, it's the least I could do. $\endgroup$
    – Candle
    Jan 20, 2022 at 2:55

You must log in to answer this question.

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