Forum

Author Topic: Equivalent of Tools > Import > Import Markers in python scripting?  (Read 8597 times)

halde_vincent

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hello everyone,

This may be a easy question, but how can I do the equivalent of:
Tools > Import > Import Markers
in python scripting?

Thank you!

Vincent

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #1 on: April 27, 2014, 06:44:58 PM »
Hello Vincent,

Currently there's no Import Markers function equivalent in Python API, so this feature is to be added in one of the next updates.
Best regards,
Alexey Pasumansky,
Agisoft LLC

theYesMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #2 on: May 06, 2014, 01:47:20 AM »
Hi Alexey,

>> this feature is to be added in one of the next updates.

Do you have an estimate to this next update?

Thanks.

theYesMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #3 on: May 06, 2014, 01:50:57 AM »
Hi Alexey,

>> this feature is to be added in one of the next updates.

Until this update is released, is there a current work-around, so I can input, via the Python API, the distance between each marker we have in our capture volume? If there is, would you show me an example (e.g. marker 101 xyz, marker 103 xyz, etc.)?

Thanks Alexey.

tommyboy

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #4 on: May 06, 2014, 02:59:24 AM »
+1 to this request, from a very interested Pro customer! Thank you!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #5 on: May 06, 2014, 10:53:55 AM »
For example, if you have list of coordinates represented as tuples I can suggest the following code, providing that markers have been already created:

Code: [Select]
doc  = PhotoScan.app.document
chunk = activeChunk

coordinate_list = [(93.33312, 24.565464, 178.5), (93.4657, 24.7345, 175.23)]
#list of tuples with the coordinates to be imported

markers = chunk.markers
locations = chunk.ground_control.locations

for i in range(len(markers)):
    marker = markers[i]
    marker_coords = locations[marker]
    marker_coords  = coordinate_list[i]
   
chunk.ground_control.apply()
PhotoScan.app.update()
Best regards,
Alexey Pasumansky,
Agisoft LLC

theYesMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #6 on: May 13, 2014, 12:31:08 AM »
Hi Alexey,

Thank you for the reply. I ended up using

    PhotoScan.Chunk.ground_control.load ( MARKER_TEXT_FILE, 'csv' )

That seems to be the same as Tools -> Import -> Import Markers

theYesMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #7 on: May 13, 2014, 01:43:17 AM »
Hi Alexey,

I spoke too soon. The function I was looking for is found under the Ground Control panel. In this panel, on the upper left corner, there is an icon button named "Import". This of course is not the same as "Tools -> Import Markers....." Sorry for the confusion.

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #8 on: December 06, 2017, 08:03:34 PM »
Hello Vincent,

Currently there's no Import Markers function equivalent in Python API, so this feature is to be added in one of the next updates.

Any news on this matter? I have an Agisoft Markers file (*.xml) I would like to import via Python scripting.
Luiz Fernando

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #9 on: December 06, 2017, 08:20:28 PM »
Found out here!

http://www.agisoft.com/forum/index.php?topic=5073.msg25218
UPDATE: the code found in the above post is outdated (v1.2) as Alexey mentions bellow.
« Last Edit: December 06, 2017, 09:12:53 PM by lfsantosgeo »
Luiz Fernando

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #10 on: December 06, 2017, 08:30:34 PM »
Hello lfsantosgeo,

In the version 1.3 you need to use the following code:
Code: [Select]
chunk.loadReference(path, format=PhotoScan.ReferenceFormatXML)The information in the thread you are referring to is outdated and related to the version 1.2.
Best regards,
Alexey Pasumansky,
Agisoft LLC

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #11 on: December 06, 2017, 09:19:22 PM »
Thank you Alexey! So it would look like the below code?

UPDATE: updated the code without the boolean output using the suggestion from Alexey's below comment to use try-except convention
Code: [Select]
   import_markersXML = PhotoScan.app.getOpenFileName ("Add your PhotoScan Markers XML file:")
      if not import_markersXML:
             print("Script aborted")
             return 0   

   chunk = PhotoScan.app.document.chunk

try:
    chunk.loadReference(import_markersXML, format=PhotoScan.ReferenceFormatXML)
except:
    print("something happened")
 
   #update
   chunk.updateTransform()
   PhotoScan.app.update()

« Last Edit: December 06, 2017, 11:01:21 PM by lfsantosgeo »
Luiz Fernando

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #12 on: December 06, 2017, 09:36:34 PM »
Hello lfsantosgeo,

I think so, but instead of boolOut check I'd rather suggest to use try - except convention, if you wish to catch any exception, since loadReference() function in 1.3 doesn't return any Boolean value:
Code: [Select]
try:
    chunk.loadReference(path)
except:
    print("something happened")
Best regards,
Alexey Pasumansky,
Agisoft LLC

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #13 on: December 06, 2017, 10:55:32 PM »
Thank you Alexey! I'll try this try-except convention instead. Updated the code above to insert it.

What about this (got from the Python API):


Quote
importMarkers(path)
   Import markers.
   Parameters path (string) – Path to the file


Code: [Select]
try:
    chunk.importMarkers(path)
except:
    print("something happened")

I read on the post I referred to that loadReference() is for the import function from the Reference Pane not from Tools > Import > Import Markers... Actually that is what you've posted there.

http://www.agisoft.com/forum/index.php?topic=5073.msg25218
UPDATE: the code found in the above post is outdated (v1.2) as Alexey mentions bellow.

Anyway the above code with the loadReference() function gives the except error message. It won't import the *.xml file for markers.

I also have found an old version code to import markers as stated on the following post:
http://www.agisoft.com/forum/index.php?topic=3844.0
« Last Edit: December 08, 2017, 03:39:00 PM by lfsantosgeo »
Luiz Fernando

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Equivalent of Tools > Import > Import Markers in python scripting?
« Reply #14 on: December 08, 2017, 04:41:26 PM »
Hello lfsantosgeo,

Yes, I thought you were speaking about Reference import, since you were referring to the thread where the marker information has been load to the Reference pane.

If you need to use the analogue of Tools Menu -> Import Markers (or File Menu -> Import Markers in the version 1.4), then you need to use the following:
Code: [Select]
chunk.importMarkers(path)
« Last Edit: December 08, 2017, 04:42:57 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC