Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: Michel on June 21, 2022, 01:39:00 PM

Title: Deleting empty camera groups
Post by: Michel on June 21, 2022, 01:39:00 PM
Hello everyone,

I am looking for a method to delete empty camera groups automatically. From a practical point of view, I know that we need to create a list of group we want to remove, then use the chunk.remove() function. However, the Metashape.CameraGroup class doesn't have a function to know if the group is empty or not. Do you have any idea how to do this?

Thank you,
--
Michel
Title: Re: Deleting empty camera groups
Post by: Alexey Pasumansky on June 21, 2022, 02:34:58 PM
Hello Michel,

Try this one:

Code: [Select]
chunk = Metashape.app.document.chunk
empty = list(chunk.camera_groups)
for camera in chunk.cameras:
    if camera.group in empty:
        empty.remove(camera.group)
chunk.remove(empty)
Title: Re: Deleting empty camera groups
Post by: Michel on June 21, 2022, 02:55:29 PM
Hello Alexey,

Thank you for your help, this method works perfectly.

I would like to put a corrected version where I replaced the list a by empty, otherwise it does not work  ;)

Code: [Select]
chunk = Metashape.app.document.chunk
empty = list(chunk.camera_groups)
for camera in chunk.cameras:
    if camera.group in empty:
        empty.remove(camera.group)
chunk.remove(empty)

--
Michel
Title: Re: Deleting empty camera groups
Post by: Alexey Pasumansky on June 21, 2022, 06:29:10 PM
Sure, thanks Michel, I will fix that.