Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: eastonmbio 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:
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.
-
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
batch_id = client.createBatch(path[len(root):], [network_tasks] )
into
batch_id = client.createBatch(path[len(root):], network_tasks)