Forum

Author Topic: RunScript NetworkTask how to?  (Read 5490 times)

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
RunScript NetworkTask how to?
« on: May 04, 2016, 11:03:58 AM »
Hi,
  we are working on networking and we want to run Python scripts on network. Can you please provide an example how to perform RunScript task from Python, and how to access PhotoScan data from that script?

Best regards,
Srdjan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15029
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #1 on: May 05, 2016, 06:07:51 PM »
Hello Srdjan,

here's the script that starts another python script as a network task:

Code: [Select]
import PhotoScan

client = PhotoScan.NetworkClient()

task1 = PhotoScan.NetworkTask()
task1.name = 'RunScript'
task1.params['path'] = "processing/script.py" #path to the script to be executed
task1.params['args'] = "argument1 argument2" #string of the arguments with space as separator

path = "processing/project.psx"
client.connect('192.168.0.2') #server ip
batch_id = client.createBatch(path, [task1])
client.resumeBatch(batch_id)
print("Job started...")


and here's the script.py that should be executed as a network task (just a simple example):
Code: [Select]
import PhotoScan, sys

args = sys.argv
label = args[1] #the very first argument is the script path

doc = PhotoScan.app.document
chunk = doc.chunk
chunk.label = label
Best regards,
Alexey Pasumansky,
Agisoft LLC

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #2 on: May 06, 2016, 12:53:54 PM »
Hi,
  unfortunately, script called by RunScript task results in error. It seems that PhotoScan.app.document is None no matter which psx file it is called on. Can you please check?

Best regards,
Srdjan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15029
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #3 on: May 06, 2016, 12:58:41 PM »
Hello Srdjan,

It seems to be an issue in the version 1.2.4 build 2399 that will be fixed in the next update. Actually I was testing the script on the internal version where it has been already fixed. Sorry for the inconvenience.
Best regards,
Alexey Pasumansky,
Agisoft LLC

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #4 on: May 06, 2016, 01:11:17 PM »
Okay, can you tell me when we can except this new version? and are there workarounds in current version?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15029
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #5 on: May 06, 2016, 02:50:00 PM »
I think we'll release the new version this month. As a workaround you can pass full path to the document among the script arguments and open the document in the working script via doc.open(), however, the path should be absolute and this workaround may fail if there are multiple processing nodes that see the script file under different absolute paths (for example, if there's a mixture of OS).
Best regards,
Alexey Pasumansky,
Agisoft LLC

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #6 on: May 09, 2016, 11:09:49 AM »
Thank you Alexey. Regarding the workaround, is there a way to for RunScript network task to work on multichunk project so that it will be executed on every chunk (script code is called for each chunk (like for standard functions))?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15029
    • View Profile
Re: RunScript NetworkTask how to?
« Reply #7 on: May 10, 2016, 05:26:14 PM »
Hello Srdjan,

Having access to the active document should allow you to perform some custom operations for any or every chunk in this document.
Best regards,
Alexey Pasumansky,
Agisoft LLC