Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Last active May 20, 2024 20:31
Show Gist options
  • Save BigRoy/072927ca6b13655bb9f0122f7b3f25ec to your computer and use it in GitHub Desktop.
Save BigRoy/072927ca6b13655bb9f0122f7b3f25ec to your computer and use it in GitHub Desktop.
Python script using Alembic api to detect whether an .abc file contains any shapes.
import alembic
def any_shapes_in_alembic(filename):
"""Return whether Alembic file contains any shape/geometry.
Arguments:
filename (str): Full path to Alembic archive to read.
Returns:
bool: Whether Alembic file contains geometry.
"""
# Also see:
# https://github.com/rsgalloway/alembic/blob/cask-dev/python/examples/cask/cask.py
SHAPES = [alembic.AbcGeom.IPolyMesh,
alembic.AbcGeom.ICurves,
alembic.AbcGeom.ISubD,
alembic.AbcGeom.IPoints]
filename = str(filename) # ensure str
archive = alembic.Abc.IArchive(filename)
root = archive.getTop()
iterator = list(root.children)
for obj in iterator:
md = obj.getMetaData()
if any(shape.matches(md) for shape in SHAPES):
return True
# include children for coming iterations
iterator.extend(obj.children)
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment