Alembic Python : documentation and examples ?

66 views
Skip to first unread message

Nicholas Yue

unread,
Apr 1, 2025, 5:22:14 PMApr 1
to alembic-discussion
Hi,

I would like to learn more about using the alembic python module.

Where can I find documentation and examples ?

Kind regards
--

Lucas Miller

unread,
Apr 1, 2025, 5:25:36 PMApr 1
to alembic-d...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "alembic-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alembic-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/alembic-discussion/CADYXiJLfGaBj_erPAahZHDnM2Xoq7ixPrHzbe1nf-Jse7e5v0w%40mail.gmail.com.

Nicholas Yue

unread,
Apr 1, 2025, 7:47:04 PMApr 1
to alembic-d...@googlegroups.com
Adapting from the unit test code, I have the following

====================================================
if __name__ == "__main__":
    print("len(sys.argv) = ", len(sys.argv))
    if len(sys.argv) != 3:
        print("Usage: python query_camera.py <camera_abc> <cam_name>")
        sys.exit(1)

    camera_abc = sys.argv[1]
    cam_name = sys.argv[2]

    print("camera_abc = ", camera_abc)
    print("cam_name = ", cam_name)

    archive = IArchive(camera_abc)
    identity = M33d()
    identity.makeIdentity()

    samp = CameraSample()

    cam = ICamera(archive.getTop(), cam_name) # FAILED HERE

    assert cam
    assert cam.valid()
====================================================

But the code is having difficult with a camera that was exported for me

Using abcecho, I did a dump to text to illustrate it's content

====================================================
AbcEcho for Alembic 1.8.8 (built Apr  1 2025 14:12:49)
  file written by: Maya 2023 AbcExport v1.0
  using Alembic : Alembic 1.8.3 (built Aug  3 2022 14:35:12)
  written on : Tue Apr  1 09:52:00 2025
  user description : Exported from: somefile.ma

  ScalarProperty name=.childBnds;interpretation=box;datatype=float64_t[6];arraysize=6;numsamps=98
  ScalarProperty name=statistics;interpretation=;datatype=string;arraysize=1;numsamps=1
  ScalarProperty name=1.samples;interpretation=;datatype=uint32_t;arraysize=1;numsamps=1
Object name=/previsCamera_i001:shotcam
  CompoundProperty name=.xform;schema=AbcGeom_Xform_v3
    ScalarProperty name=.inherits;interpretation=;datatype=bool_t;arraysize=1;numsamps=1
    ScalarProperty name=.ops;interpretation=;datatype=uint8_t[5];arraysize=5;numsamps=1
    ScalarProperty name=.vals;interpretation=;datatype=float64_t[9];arraysize=9;numsamps=1
    ScalarProperty name=isNotConstantIdentity;interpretation=;datatype=bool_t;arraysize=1;numsamps=1
Object name=/previsCamera_i001:shotcam/previsCamera_i001:shotcamShape
  CompoundProperty name=.geom;schema=AbcGeom_Camera_v1
    ScalarProperty name=.core;interpretation=;datatype=float64_t[16];arraysize=16;numsamps=98
    ScalarProperty name=.filmBackOps;interpretation=;datatype=string[5];arraysize=5;numsamps=1
    ScalarProperty name=.filmBackChannels;interpretation=;datatype=float64_t[10];arraysize=10;numsamps=98

   .... remain stuff deleted for brevity
====================================================

I am calling my script with the following arguments

====================================================
python3 query_dof_camera.py previsCamera_i001_playblast_v007.abc " /previsCamera_i001:shotcam/previsCamera_i001:shotcamShape"
====================================================

I get the error

====================================================
len(sys.argv) =  3
camera_abc =  previsCamera_i001_playblast_v007.abc
cam_name =   /previsCamera_i001:shotcam/previsCamera_i001:shotcamShape
Traceback (most recent call last):
  File "/home/nyue/temp/andrew_alembic_camera_fstop/query_dof_camera.py", line 59, in <module>
    cam = ICamera(archive.getTop(), cam_name)
RuntimeError: ISchemaObject::ISchemaObject( IObject )
ERROR: EXCEPTION:
Bad child:  /previsCamera_i001:shotcam/previsCamera_i001:shotcamShape
====================================================


Lucas Miller

unread,
Apr 1, 2025, 8:32:44 PMApr 1
to alembic-d...@googlegroups.com
The ICamera constructor doesn't try to traverse the hierarchy fo you, so instead you have to do something like:

cam  = ICamera(archive.getTop().getChildByName('previsCamera_i001:shotcam'), 'previsCamera_i001:shotcamShape')

Nicholas Yue

unread,
Apr 2, 2025, 12:59:06 PMApr 2
to alembic-d...@googlegroups.com
I tried this

    ## Code from Lucas to illustrate the issue

    cam = ICamera(archive.getTop().getChildByName('previsCamera_i001:shotcam'), 'previsCamera_i001:shotcamShape')

I get the error


Traceback (most recent call last):
  File "/home/nyue/temp/johndoe_alembic_camera_fstop/query_dof_camera.py", line 68, in <module>

    cam = ICamera(archive.getTop().getChildByName('previsCamera_i001:shotcam'), 'previsCamera_i001:shotcamShape')
AttributeError: 'IObject' object has no attribute 'getChildByName'. Did you mean: 'getChildHeader'?

Lucas Miller

unread,
Apr 2, 2025, 1:10:50 PMApr 2
to alembic-d...@googlegroups.com
Try this:

cam = ICamera(archive.getTop().getChild('previsCamera_i001:shotcam'), 'previsCamera_i001:shotcamShape')

Nicholas Yue

unread,
Apr 2, 2025, 4:25:10 PMApr 2
to alembic-d...@googlegroups.com
Thank you Lucas.

It's working now.

Kind regards

Reply all
Reply to author
Forward
0 new messages