7
$\begingroup$

I am in the process of writing a tool that makes uses of Sequences in the Sequence Editor. I was trying the following in my add-on (register() method)

Sequence.active = BoolProperty(name='Active', 
                               description='Is the custom property group active', 
                               default=True)`

After I launch Blender and try to assign a value to my custom property, I get the following error

>>> C.scene.sequence_editor.sequences[0].active = 1
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'SceneSequence' object attribute 'active' is read-only

So my question is: Is it possible in anyway to add a custom property to a Sequence?

$\endgroup$

1 Answer 1

13
$\begingroup$

Update: bpy.types.Sequence
Properties is supported in 2.75 (or recent builds)

The information below is kept since the answer still applies to types such as bpy.types.TimelineMarker or bpy.types.Modifier.


In short - no. You can only add custom data properties on:

  • ID (its subclasses Action, Armature, Brush, Camera, Curve, FreestyleLineStyle, GreasePencil, Group, Image, Key, Lamp, Lattice, Library, Mask, Material, Mesh, MetaBall, MovieClip, NodeTree, Object, PaintCurve, Palette, ParticleSettings, Scene, Screen, Sound, Speaker, Text, Texture, VectorFont, WindowManager, World', etc...)
    Try run: bpy.types.ID.__subclasses__() to see all.
  • Bones
  • PoseBones
  • AddonPrefs
  • Node, NodeSocket, NodeSocketInterface
  • OperatorProperties.

The reason this gives confusing output is that the initial assignment is using Pythons regular class assignment, in this case its not using a metaclass (which would interpret the property definitions and apply them as you are expecting).

bpy.types.Sequence.foobar = 22
print(bpy.context.sequences[0].foobar)
# >>> 22
bpy.context.sequences[0].foobar = 11 # <-- will error!
# AttributeError: 'SceneSequence' object attribute 'foobar' is read-only

So why use this at all? - Because it allows you to add utility methods & properties at run-time. Note that this is standard python and nothing Blender specific (unlike custom properties).

bpy.types.Sequence.calc_frame_mid = (lambda seq:
        (seq.frame_final_start + seq.frame_final_end) / 2)

print(bpy.context.sequences[0].calc_frame_mid())

... you can add Python style properties too.

Note, adding methods and properties to existing data types is known as Monkey Patching and often considered bad practice, however you can also use this to dynamically build up functionality into classes you generate for instance, so it can be used in some interesting/useful ways too.

If you modify Blenders built in types it will make the changes globally so beware it could break other scripts or even make Blender fail to use its own API's correctly, so this is really advanced api usage.

$\endgroup$
3
  • $\begingroup$ +1 Thank you for the response and some insights into properties. I will look into this and see if i can implement a workable solution for my addon. $\endgroup$
    – satishgoda
    Jun 18, 2013 at 5:26
  • $\begingroup$ Thank you again for the extra note. Will keep that in mind and test accordingly. $\endgroup$
    – satishgoda
    Jun 18, 2013 at 15:24
  • 1
    $\begingroup$ Update, in 275 you can do this! $\endgroup$
    – ideasman42
    Apr 25, 2015 at 14:20

You must log in to answer this question.

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