markreidvfx / pyavb

Read and write Avid Bin FIles (AVB) files
https://pyavb.readthedocs.io
MIT License
58 stars 4 forks source link

Allow copying of mobs from one avb to another #9

Closed cbenhagen closed 1 year ago

cbenhagen commented 3 years ago

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 commented 3 years ago

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.

markreidvfx commented 2 years ago

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.

russellaugust commented 1 year ago

@cbenhagen did you ever make progress with this?

cbenhagen commented 1 year ago

No unfortunately not.

markreidvfx commented 1 year ago

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

mjiggidy commented 1 year ago

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