Forum

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

tymal77

  • Newbie
  • *
  • Posts: 4
    • View Profile
How to run script in a loop with arguments????
« on: March 20, 2019, 01:44:43 PM »
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
    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.
« Last Edit: May 28, 2019, 06:49:11 PM by Alexey Pasumansky »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to run script in a loop with arguments????
« Reply #1 on: March 20, 2019, 01:51:58 PM »
Hello tymal77,

I would rather suggest to modify your source script and make the core functionality to work as a function that gets the chunk as an argument:

Code: [Select]
def my_func(chunk):
    ....

Then apply it to the chunks:

Code: [Select]
for i in range(3,18):
    chunk = doc.chunks[i]
    my_funk(chunk)
Best regards,
Alexey Pasumansky,
Agisoft LLC