pyavb icon indicating copy to clipboard operation
pyavb copied to clipboard

Allow copying of mobs from one avb to another

Open cbenhagen opened this issue 4 years ago • 2 comments

It would be nice if this would work:

with avb.open("source.avb") as f:
    with avb.open() as f2:
        for mob in f.content.mobs:
            f2.content.add_mob(mob)
        f2.write("destination.avb")

This currently results in:

Traceback (most recent call last):
  File "/path/to/script.py", line 42, in <module>
    f2.write("destination.avb")
  File "/Users/ben/.local/share/virtualenvs/avid_bin-DIzLLTwC/lib/python3.8/site-packages/avb/file.py", line 311, in write
    self.write_object(f, obj)
  File "/Users/ben/.local/share/virtualenvs/avid_bin-DIzLLTwC/lib/python3.8/site-packages/avb/file.py", line 278, in write_object
    obj.write(buffer)
  File "/Users/ben/.local/share/virtualenvs/avid_bin-DIzLLTwC/lib/python3.8/site-packages/avb/attributes.py", line 82, in write
    ctx = self.root.octx
AttributeError: 'AVBFile' object has no attribute 'octx'

cbenhagen avatar Jun 22 '21 14:06 cbenhagen

To give this some context: The goal for us would be to copy clips from daily sync bins to scene bins. It would be nice if the mobs would not need to be re-created from scratch. Any guidance on how to achieve this would be much appreciated. I am happy to contribute the final script back as an example.

cbenhagen avatar Jun 22 '21 14:06 cbenhagen

Yes this would be nice. Its a little involved because a mob references other mobs and objects. Those need to get copied as well for avid to to complain or crash.

markreidvfx avatar Jun 13 '22 20:06 markreidvfx

@cbenhagen did you ever make progress with this?

russellaugust avatar Oct 23 '22 14:10 russellaugust

No unfortunately not.

cbenhagen avatar Oct 23 '22 14:10 cbenhagen

This is now possible in the 1.4 release.
All AVBObjects now have a copy method, that can change the root object to another file. The method handles all the tricky dependent references too.


with avb.open("source.avb") as a:
    with avb.open() as b:
        for mob in a.content.mobs:
            new_mob = mob.copy(b)
            b.content.add_mob(new_mob)
        b.write("dest.avb")

mobs also have a dependant_mobs method too that returns mob dependencies.

for more examples look at test_copy.py

markreidvfx avatar Jul 05 '23 03:07 markreidvfx

This is gonna be big for me! Thank you so much!

mjiggidy avatar Jul 05 '23 03:07 mjiggidy