Forum

Author Topic: Removing markers from selected cameras (python)  (Read 4891 times)

Mycobiont

  • Newbie
  • *
  • Posts: 21
    • View Profile
Removing markers from selected cameras (python)
« on: February 03, 2021, 04:59:16 AM »
I'm trying to script the removal of markers that have been placed on selected photos.  I can get them to go from green to blue, and I've seen other scripts for removing blue markers, so I thought it should be simple to combine the two concepts.  But it isn't working.  The following shifts them to blue but does not remove them.  Any suggestions?

Code: [Select]
def cameraMarkerClear():
        print("Clearing markers from selected cameras...", flush=True)
        chunk = doc.chunk
        countCams = 0
        countMarks = 0
        for camera in chunk.cameras:
                if camera.selected:
                        countCams = countCams + 1
                        for marker in chunk.markers:
                                proj = marker.projections[camera]
                                if proj is not None:
                                        if proj.pinned:
                                                countMarks = countMarks + 1
                                                proj.pinned = False  ### this turns them from green to blue
                                                proj = None  ### this should be what other scripts use to remove blue markers
                                                print("removing " + marker.label + " from " + camera.label, flush = True)
                       
        print("Removed " + str(countMarks) + " markers from " + str(countCams) + " cameras.")

app.addMenuItem("Testing/Clear Markers From Selected Cameras", cameraMarkerClear)

Thanks!

Paulo

  • Hero Member
  • *****
  • Posts: 1362
    • View Profile
Re: Removing markers from selected cameras (python)
« Reply #1 on: February 03, 2021, 07:02:11 AM »
Hi Mycobiont,

try using marker.projections[camera] = None instead of proj = None
Best Regards,
Paul Pelletier,
Surveyor

Mycobiont

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Removing markers from selected cameras (python)
« Reply #2 on: February 03, 2021, 09:24:02 PM »
Perfect - thank you Paulo!

Functioning script for the record:
Code: [Select]
def cameraMarkerClear():
        print("Clearing markers from selected cameras...", flush=True)
        chunk = doc.chunk
        countCams = 0
        countMarks = 0
        for camera in chunk.cameras:
                if camera.selected:
                        countCams = countCams + 1
                        for marker in chunk.markers:
                                proj = marker.projections[camera]
                                if proj is not None:
                                        if proj.pinned:
                                                countMarks = countMarks + 1
                                                marker.projections[camera] = None
                                                print("removing " + marker.label + " from " + camera.label, flush = True)
                       
        print("Removed " + str(countMarks) + " markers from " + str(countCams) + " cameras.")

app.addMenuItem("Testing/Clear Markers From Selected Cameras", cameraMarkerClear)

ArchArch

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Removing markers from selected cameras (python)
« Reply #3 on: April 11, 2023, 05:25:26 PM »
I am new to scripting in the console but would love to be able to automate this step. When I copy and paste the shared script (thanks!) into the console and hit return I get "NameError: name 'app' is not defined". What would a newbie need to know to use the script? Thank you!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Removing markers from selected cameras (python)
« Reply #4 on: April 12, 2023, 04:10:33 PM »
Hello ArchArch,

You should modify it to:
Metashape.app.addMenuItem("Testing/Clear Markers From Selected Cameras", cameraMarkerClear)

But if any further error appears, please provide the console output. Probably this two-year-old script should be adapted to the latest API version.
Best regards,
Alexey Pasumansky,
Agisoft LLC