Forum

Author Topic: Deleting empty camera groups  (Read 677 times)

Michel

  • Newbie
  • *
  • Posts: 14
    • View Profile
Deleting empty camera groups
« 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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13990
    • View Profile
Re: Deleting empty camera groups
« Reply #1 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)
« Last Edit: June 21, 2022, 06:29:23 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

Michel

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Deleting empty camera groups
« Reply #2 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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13990
    • View Profile
Re: Deleting empty camera groups
« Reply #3 on: June 21, 2022, 06:29:10 PM »
Sure, thanks Michel, I will fix that.
Best regards,
Alexey Pasumansky,
Agisoft LLC