Forum

Author Topic: How to run script in a loop with arguments?  (Read 1590 times)

andyroo

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
How to run script in a loop with arguments?
« on: November 08, 2018, 05:31:31 AM »
I have a nice script I want to run on a bunch of chunks in a project, but can't figure out how to call it properly from the console. I'd like to be able to use it on selected chunks in selected projects whenever I want, but it's fairly complex (for me) to do that outside of the console.

What I would like to do is run a script on a subset of my chunks by first activating a chunk, then running a python script with arguments that works on the active chunk, like this:

Code: [Select]
for i in range(3,18):
    doc.chunk = doc.chunks[i]
    task.runscript('c:\my_cheesy_scripts\make_awesome.py', args)

I reviewed methods to do this online and they suggest  subprocess.call or execfile, but I can't figure out how to do either one within the PhotoScan console. So I'm left clicking "Run script" and activating each chunk, which is tedious.

Any help is appreciated.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to run script in a loop with arguments?
« Reply #1 on: November 08, 2018, 12:20:34 PM »
Hello andyroo,

In case you wish to call some external script that performs some action with the project/chunk, you should modify it to be able to pass the project path and chunk index as an argument.

If the script, however, makes something with the active chunk of the active document, then you can do the following:

Code: [Select]
doc = PhotoScan.app.document.chunk
for i in range(3,18):
    doc.chunk = doc.chunks[i]
    task = PhotoScan.Tasks.RunScript()
    task.path = 'c:\my_cheesy_scripts\make_awesome.py'
    task.args = args
    task.apply(doc)
Best regards,
Alexey Pasumansky,
Agisoft LLC