Linking an object to a property

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Chazney
Posts: 0
Joined: Fri Jun 21, 2013 12:38 am

Linking an object to a property

Post by Chazney »

Hi,

I want to link an object in some way via a property (much like the way an Object has a parent property to another Object), either directly or through an object name. I can use a StringProperty to store the name of the object, but of course this does not get updated when the object changes it's name.

Here is the scenario I have. An animation is a collection of actions linked to objects. I want to be able to save the current animation setup inside the scene, so that I have a list of animation setups aside from the current animation setup. This means I need a collection of properties that contain both the object and the action linked to that object.

So, here is the class that links the actions/objects:

Code: Select all

class ActionObjectLinkPropertyGroup(bpy.types.PropertyGroup):
    # Here is where I want to link directly to the action or object, since these properties are not updated when the action/object name updates.
    action_name = bpy.props.StringProperty(\
        default="")
        
    object_name = bpy.props.StringProperty(\
        default="")
An animation itself is a collection of this property:

Code: Select all

class AnimPropertyGroup(bpy.types.PropertyGroup):
    action_object_links = bpy.props.CollectionProperty(\
        type=ActionObjectLinkPropertyGroup)
And finally, I store a collection of this property in the current scene:

Code: Select all

bpy.types.Scene.animations = bpy.props.CollectionProperty(\
    type=AnimPropertyGroup)
This is fine, until I decide to change the name of the objects.

I am wondering if there is a way to either detect a name update (I have tried object.is_updated, this doesn't seem to be set to true when only the name changes), or directly store the object to directly reference the name through object.name.

The only other thing I could think of is storing the name used by the animations as a separate StringProperty inside the object itself, and when the name changes, I can compare that property with the name and update accordingly. This can work, but I am wondering if there is a better way to maintain matching names.

Hopefully I explained this well enough.[/code]

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

I'm sitting, waiting, wishing, building Blender in superstition...

Chazney
Posts: 0
Joined: Fri Jun 21, 2013 12:38 am

Post by Chazney »

Yes, that is what I mentioned at the end of my post. I was just wondering if there was a better way, but it seems not (at least for now).

Thanks!

Post Reply