Skip to content

Instantly share code, notes, and snippets.

@twilson90
Created March 31, 2019 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twilson90/634ea03acd2a1d87f99fbb06857e1956 to your computer and use it in GitHub Desktop.
Save twilson90/634ea03acd2a1d87f99fbb06857e1956 to your computer and use it in GitHub Desktop.
a helpful function for finding most of the animation datas used in a context or scene
def get_anim_datas(context=None):
if context is None: context = bpy.context
found = set()
materials = set()
textures = set()
def found_add(o):
if o is None: raise Exception()
found.add(o)
found_add(context.scene)
found_add(context.scene.world)
for o in context.scene.objects:
found_add(o)
if o.data is not None:
found_add(o.data)
for ms in o.material_slots:
if ms.material is not None:
materials.add(ms.material)
if hasattr(o.data, "materials"): materials.update(o.data.materials)
if isinstance(o.data, (bpy.types.Curve, bpy.types.Mesh, bpy.types.Lattice)):
if o.data.shape_keys is not None: found_add(o.data.shape_keys)
for m in o.modifiers:
if isinstance(m, (bpy.types.MeshSequenceCacheModifier, bpy.types.TransformCacheConstraint)):
found_add(m.cache_file)
if isinstance(m, (bpy.types.DisplaceModifier, bpy.types.WarpModifier, bpy.types.WaveModifier)):
found_add(m.texture)
if isinstance(m, (bpy.types.VertexWeightEditModifier, bpy.types.VertexWeightMixModifier, bpy.types.VertexWeightProximityModifier)):
found_add(m.mask_texture)
for ps in o.particle_systems:
found_add(ps.settings)
for m in materials:
if m.node_tree:
found_add(m.node_tree)
for n in m.node_tree.nodes:
if isinstance(n, (bpy.types.CompositorNodeTexture, bpy.types.TextureNodeTexture)):
textures.add(n.texture)
if context.sequences is not None:
for s in context.sequences:
if isinstance(s, bpy.typesMaskSequence) and s.mask: found_add(s.mask)
if hasattr(context, "speaker") and context.speaker is not None:
found_add(context.speaker)
for ls in context.view_layer.freestyle_settings.linesets:
found_add(ls.linestyle)
found.update(materials)
found.update(textures)
for f in found:
if f.animation_data is not None:
yield f.animation_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment