50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import bpy
|
|
|
|
from ...core import Check, Issue, contexts, is_local
|
|
|
|
_ANIMATABLE = [
|
|
"objects", "meshes", "curves", "armatures", "grease_pencils", "materials",
|
|
"node_groups", "shape_keys", "cameras", "lights", "worlds", "scenes",
|
|
]
|
|
|
|
|
|
def _animated_ids():
|
|
for collection_name in _ANIMATABLE:
|
|
for id_block in getattr(bpy.data, collection_name, ()):
|
|
if not is_local(id_block):
|
|
continue
|
|
ad = id_block.animation_data
|
|
if ad is not None and (ad.action is not None or len(ad.nla_tracks)):
|
|
yield id_block, ad
|
|
|
|
|
|
class AnimationCheck(Check):
|
|
id = "animation"
|
|
label = "No animation"
|
|
description = "No action or NLA track is assigned (drivers are allowed)."
|
|
category = "Animation"
|
|
contexts = contexts.ASSET
|
|
fix_description = "Unassign actions and remove NLA tracks (drivers are kept)"
|
|
|
|
def run(self, ctx):
|
|
for id_block, ad in _animated_ids():
|
|
parts = []
|
|
if ad.action is not None:
|
|
parts.append(f"action '{ad.action.name}'")
|
|
if len(ad.nla_tracks):
|
|
parts.append(f"{len(ad.nla_tracks)} NLA track(s)")
|
|
name = id_block.user.name if isinstance(id_block, bpy.types.Key) else id_block.name
|
|
yield Issue.for_id(f"{name}: {', '.join(parts)}", id_block)
|
|
|
|
def fix(self, ctx, issues):
|
|
for issue in issues:
|
|
id_block = issue.get_id()
|
|
ad = id_block.animation_data if id_block is not None else None
|
|
if ad is None:
|
|
continue
|
|
ad.action = None
|
|
for track in list(ad.nla_tracks):
|
|
ad.nla_tracks.remove(track)
|
|
if not len(ad.drivers):
|
|
id_block.animation_data_clear()
|