Forum

Author Topic: RunScript to execute external script version 1.5.1  (Read 2343 times)

eastonmbio

  • Newbie
  • *
  • Posts: 13
    • View Profile
RunScript to execute external script version 1.5.1
« on: April 12, 2021, 12:47:57 PM »
I'm looking to execute an external script as a network task using the following tester code:

Code: [Select]
import Metashape

path = Metashape.app.getOpenFileName("Specify path to the PSX document:")
root = Metashape.app.getExistingDirectory("Specify network root path:")

doc = Metashape.Document()
doc.open(path)
chunk = doc.chunk

client=Metashape.NetworkClient()

network_tasks = list()

task = Metashape.Tasks.RunScript()
task.path = "C:/path/to/myscript.py"

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)


client.connect('my.server.name')
batch_id = client.createBatch(path[len(root):], [network_tasks] )
client.resumeBatch(batch_id)
print("Job Started...")


The code referred to in the path just imports Metashape. However, when running the script, I get the error message " TypeError: Task object expected". Clearly what I am passing in to the server is not recognised as a task. I am using version 1.5.1. I'm not sure if my code structure needs to change to accommodate network processing of the external script.

MoWo

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: RunScript to execute external script version 1.5.1
« Reply #1 on: March 02, 2023, 11:28:27 AM »
I am absolutely sure that the issue has been resolved - Still have the solution to your problem as I ran into the same error - Maybe it will help others in the future.

You have the 'network_tasks' wrapped in a nested list (possibly a copy-paste error like mine).

You should change that line
Code: [Select]
batch_id = client.createBatch(path[len(root):], [network_tasks] )
into
Code: [Select]
batch_id = client.createBatch(path[len(root):], network_tasks)