cask – Alembic Python Convenience Wrapper

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

Arguably one of the biggest conveniences is that cask handles all the OObject and OProperty bookkeeping for you, keeping these objects in scope until you call an explicit “save()” method. Some of the other features are listed below.

  • Abstraction layer for I and O object types,
  • Automatically schemify objects on read,
  • Deferred writing / cached reading,
  • Auto convert python data types to alembic data types,
  • Deep dictionary access for objects and properties.

Tutorial

Since cask abstracts “I” and “O” objects, creating a new archive or reading an existing one from disk uses the same Archive class.

>>> # read an archive from disk
>>> a = cask.Archive("lights.abc")

>>> # creates a new empty archive
>>> b = Archive()

Both objects have internal “iobject” and “oobject” properties that point to the corresponding Alembic “I” and “O” objects. For “a”, there will be an internal “iobject” property that points to the IArchive, and for “b” that property returns None. In both cases, accessing the Top object is easy, it’s just

>>> a.top
<Top "ABC">

A lot of the accessors in cask are properties vs. methods, like properties, and children, both with return dictionary-like objects. Walking and modifying the archive’s hierarchy is as simple as accessing/manipulating these dict-like objects

>>> def walk(obj):
...     print obj.name, obj.type()
...     for child in obj.children.values():
...         walk(child)
...
>>> walk(a.top)

>>> # add a new xform under the top node
>>> b.top.children["foo"] = cask.Xform()

Hierarchy Manipulation

Adding a new Object or Property is as simple as adding an object to a dictionary.

>>> a.top.children["myObject"] = cask.Xform()
>>> l.properties["myProperty"] = cask.Property()

Or you can set the parent attribute on any object:

>>> x = cask.Xform(name="foo")
>>> x.parent = a.top

Cask makes it trivial to extract an object by copying it from one archive to a new one:

>>> l.parent = b.top
>>> b.write_to_file("/var/tmp/point_light.abc")

Check the output:

> abctree /var/tmp/point_light.abc
ABC
`-- pointShape

Inserting nodes is also easy:

>>> a = cask.Archive("animatedcube.abc")
>>> r = cask.Xform()
>>> x = a.top.children["cube1"]
>>> a.top.children["root"] = r
>>> r.children["cube1"] = x
>>> a.write_to_file("/var/tmp/cask_insert_node.abc")

Check the results:

> abctree /var/tmp/cask_insert_node.abc
ABC
 `-- root
     `-- cube1
         `-- cube1Shape

Setting Values

Cask automatically converts Python data types to the appropriate Alembic typed property, or imath type using an internal map. There is no need to know which typed OProperty class to use, or potentially even which imath type you need as an argument to that property.

Currently, you can either set a value on a property directly, or create an Alembic sample object, set values on that, and then set the sample on the cask object.

Setting values directly on properties:

>>> a = cask.Archive("octopus.abc")
>>> a.top.children.values()[0].name = "squid_low"
>>> x = a.top.children.values()[0].properties[".xform/.vals"]
>>> t = imath.M33d((50, 0, 0), (0, -0, -90), (1, 1, 1))
>>> for i in range(len(x.values)):
...     x.set_value(t, index=i)

Setting values on sample objects:

>>> uvsamp = alembic.AbcGeom.OV2fGeomParamSample(meshData.uvs, kFacevaryingScope)
>>> nsamp = alembic.AbcGeom.ON3fGeomParamSample(meshData.normals, kFacevaryingScope)
>>> s = alembic.AbcGeom.OPolyMeshSchemaSample(meshData.verts, meshData.indices,
               meshData.counts, uvsamp, nsamp)
>>> p.set_sample(s)

A third way to set values is using cask wrapped methods on objects. Currently, there is only one method implemented, the setScale method on the cask.Xform class. These methods create an internal sample object and cache it, setting it on the object when save() is called. If this seems like the best, most convenient way of setting values, then we can implement more of these.

>>> x = cask.Xform()
>>> x.set_scale(imath.V3d(1, 2, 3))

Caveat: Setting samples on the object will currently only work for new, empty archives, not archives that have been read in from disk. This is a known limitation and on the to-do list to resolve.

Module Contents

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

cask.find(obj, name='.*', types=None)[source]

Finds and returns a list of Objects with names matching a given regular expression.

>>> find(a.top, ".*Shape")
[<PolyMesh "cube1Shape">, <PolyMesh "cube2Shape">]
Parameters:
  • name – Regular expression to match object name
  • types – Class type inclusion list
Returns:

Sorted list of Object results

cask.find_iter(obj, name='.*', types=None)[source]

Generator that yields Objects with names matching a given regular expression.

Parameters:
  • name – Regular expression to match object name
  • types – Class type inclusion list
Yields:

Object with name matching name regex

cask.is_valid(archive)[source]

Returns True if the archive is a valid alembic archive.

Archive

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Archive(filepath=None, fps=24)[source]

Archive I/O Object

alembic_version()[source]

Returns the version of alembic used to write this archive.

close()[source]

Closes this archive and makes it immutable.

end_frame()[source]

Returns the last frame.

end_time()[source]

Returns the global end time in seconds.

frame_range()[source]

Returns a tuple of the global start and end times in frames.

info()[source]

Returns a metadata dictionary.

iobject

Internal Alembic IArchive object.

is_leaf()[source]

Returns False.

name

Returns the basename of this archive.

oobject

Internal Alembic OArchive object.

path()[source]

Returns the filepath for this Archive.

set_start_frame(frame)[source]

Sets the start frame.

set_start_time(start)[source]

Sets the start time in seconds.

start_frame()[source]

Returns the start frame.

start_time()[source]

Returns the global start time in seconds.

time_range()[source]

Returns a tuple of the global start and end time in seconds.

** Depends on the X.samples property being set on the Top node, which is currently being written by Maya only. **

timesamplings

Generator that yields tuples of (index, TimeSampling) objects.

top

Hierarchy root, cask.Top object.

type()[source]

Returns “Archive”.

using_version()[source]

Returns the version of alembic used to read this archive.

write_to_file(filepath=None, asOgawa=True)[source]

Writes this archive to a file on disk and closes the Archive.

Object

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Object(iobject=None, schema=None, time_sampling_id=None, name=None)[source]

Base I/O Object class.

add_child(child)[source]

Adds a child object to this object.

Parameters:child – cask.Object
archive()[source]

Returns the Archive for this object.

children

Returns children sub-tree accessor.

clear_children()[source]

Clears the internal children container.

clear_properties()[source]

Clears the internal properties container.

clear_samples()[source]

Clears the internal samples container.

close()[source]

Closes this object by removing references to internal OObject.

end_frame(fps=24)[source]
Parameters:fps – Frames per second used to calculate the end frame

(default 24.0)

Returns:Last frame as float
get_item(item)[source]

used for deep dict access

global_matrix()[source]

Returns world space matrix for this object.

iobject

Internal Alembic IObject object.

is_animated()[source]

Returns True if any properties are not constant.

is_deforming()[source]

Returns True if the object has changing P values.

is_leaf()[source]

Returns True if this object is a leaf node, i.e. it has no children.

classmethod matches(iobject)[source]

Returns True if a given iobject type matches this type.

metadata

Metadata as a dict.

name

Set and get the name of the object.

oobject

Internal Alembic OObject object.

parent

Parent object accessor.

path()[source]

Returns the full path/name of this object.

properties

Properties accessor.

samples

Returns samples from the Alembic IObject.

save()[source]

Walks child and property sub-trees creating OObjects as necessary.

schema

Returns the Alembic schema object.

set_item(name, item)[source]

used for deep dict access

set_sample(sample, index=None)[source]

Sets an Alembic sample object on this object.

*Do we want to expose samples at all? Should all data be set via seting values on properties, directly or with high level methods?

Parameters:
  • sample – Alembic sample object.
  • index – Index of the sample to set, or None.
start_frame()[source]
Parameters:fps – Frames per second used to calculate the start frame

(default 24.0)

Returns:Start frame as float
time_sampling_id

Time sampling ID.

type()[source]

Returns the name of the class.

Property

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Property(iproperty=None, time_sampling_id=0, name=None, klass=None)[source]

Property I/O Object.

add_property(prop)[source]

Add a property to this, making this property a compound property.

Parameters:property – cask.Property class object.
archive()[source]

Returns the Archive for this property.

clear_properties()[source]

Clears the properties container.

clear_values()[source]

Clears the values container.

close()[source]

Closes this property by removing references to internal OProperty.

datatype

DataType object.

extent()[source]

Returns the property’s datatype extent.

get_item(item)[source]

used for deep dict access

get_value(index=None, time=None, frame=None)[source]

Returns a the value stored on this property for a given sample index, time or frame.

Provide one of the following args. If none are provided, it will return the 0th value.

Parameters:
  • index – sample index
  • time – time in seconds
  • frame – frame number (assumes 24fps, to change set on archive)
iobject

Internal Alembic IProperty object.

is_compound()[source]

Returns True if this property contains sub-properties.

Note that compound properties cannot have values, and simple properties cannont have sub-properties.

is_leaf()[source]

Returns True if this property is a leaf node, i.e. it has no sub-properties.

metadata

Metadata as a dict.

name

Gets and sets the property name.

object()[source]

Returns the object parent for this property.

oobject

Internal Alembic OProperty object.

parent

Parent object or property.

path()[source]

Returns the full path/name of this property.

pod()[source]

Returns the property’s datatype POD value.

properties

Child properties accessor.

save()[source]

Walks sub-tree and creates corresponding alembic OProperty classes, if they don’t exist, and sets values.

set_item(name, item)[source]

used for deep dict access

set_value(value, index=None, time=None, frame=None)[source]

Sets a value on the property at a given index.

Provide one of the following args. If none are provided, it will append to the end.

Parameters:
  • index – sample index
  • time – time in seconds
  • frame – frame number (assumes 24fps, to change set on archive)
type()[source]

Returns the name of the class.

values

Returns dictionary of values stored on this property.

Top

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Top(archive, iobject=None)[source]

Alembic Top Object.

is_leaf()[source]

Returns False.

classmethod matches(iobject)[source]

Returns True if iobject is a Top object.

name

Returns the object name, which for Top is always ABC

path()[source]

Returns the full path/name of this object.

Camera

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Camera(*args, **kwargs)[source]

Camera I/O Object subclass.

Curve

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Curve(*args, **kwargs)[source]

Curve I/O Object subclass.

FaceSet

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.FaceSet(*args, **kwargs)[source]

FaceSet I/O Object subclass.

Light

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Light(*args, **kwargs)[source]

Light I/O Object subclass.

Material

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Material(*args, **kwargs)[source]

Material I/O Object subclass.

NuPatch

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.NuPatch(*args, **kwargs)[source]

NuPath I/O Object subclass.

PolyMesh

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.PolyMesh(*args, **kwargs)[source]

PolyMesh I/O Object subclass.

SubD

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.SubD(*args, **kwargs)[source]

SubD I/O Object subclass.

Xform

Cask is a high level convenience wrapper for the Alembic Python API. It blurs the lines between Alembic “I” and “O” objects and properties, abstracting both into a single class object. It also wraps up a number of lower-level functions into high level convenience methods.

More information can be found at http://docs.alembic.io/python/cask.html

class cask.Xform(*args, **kwargs)[source]

Xform I/O Object subclass.

matrix(index=0)[source]

Returns the xform matrix value for a given index.

Parameters:index – Sample index.
set_scale(*args)[source]

Creates an internal XformSample object and sets the scale value.