Last active
May 20, 2024 20:31
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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