HighPerformanceAutoRouting.py - Issue

Hi everyone,

I’m new to Orthanc, but I’m using it in a fairly basic manner.
Essentially, any DICOM imaging sent to Orthanc needs to be sent straight on to a remote modality and deleted from Orthanc.
The HighPerformanceAutoRouting.py script seems ideal for this.

I’ve configured Orthanc and set-up my remote modality. I can send imaging to Orthanc, and via the web interface I can send a study to a remote modality and this works fine.

If I run the HighPerformanceAutoRouting script without anything in Orthanc, it cycles along with 0 jobs to process.
When I send imaging to Orthanc, the script sees this and then throws an error:

Current queue size: 0
Sending a packet of 3 instances
Exception in thread Thread-3:
Traceback (most recent call last):
File “C:\Python27\lib\threading.py”, line 801, in __bootstrap_inner
File “C:\Python27\lib\threading.py”, line 754, in run
self.__target(*self.__args, **self.__kwargs)
File “C:\Scripts\HighPerformanceAutoRouting.py”, line 115, in Consumer
RestToolbox.DoPost(‘%s/modalities/sample/store’ % URL, instances)
File “C:\Scripts\RestToolbox.py”, line 109, in DoPost
return _DoPutOrPost(uri, ‘POST’, data, contentType)
File “C:\Scripts\RestToolbox.py”, line 88, in _DoPutOrPost
raise Exception(resp.status)
Exception: 404

Current queue size: 0

Can someone help me resolve the error?
If I exit and re-run the script the same happens. There are 3 studies on the server at the moment, which it’s picking up and trying to send.

If there is an easier/better way to do this, perhaps via Lua, please let me know how to do this. All I need to do is forward each DICOM patient study to a remote modality when received.

P.S - Running Python 2.7 on Windows 10.

Many thanks,


Hi Craig,

Lua would be a very easy way to achieve your goal.

The first step you be to create a file, lets say is is called “forward.lua” then you can paste in this sample

function OnStoredInstance(instanceId, tags, metadata)
  Delete(SendToModality(instanceId, 'sample'))


The ‘sample’ is the name of the destination of the remote modality.

Once that file is completed and saved. You need to edit your Orthanc configuration. Not sure how the default setup is on Windows, but on Linux the default is called orthanc.json. In that json file there is a section called LuaScripts. You need to input the path of that lua script you just created into that section.

You also need to make sure that you have the remote modality set under the “list of known DICOM modalities” in the same orthanc.json file.

Here is the offical page about Lua scripting



I get that same error when my target is offline. Also, it looks like you have not edited the script with the name of your target. Sample in line 115 of the script below should be edited to the name of your target modality from your json config file. You also have to edit the URL and TARGET at the top of the script. I’m pretty new to Orthanc but try those changes and see if the script works.

File “C:\Scripts\HighPerformanceAutoRouting.py”, line 115, in Consumer
RestToolbox.DoPost(‘%s/modalities/sample/store’ % URL, instances)

This how I edited the line in my script

Send all the instances with a single DICOM connexion

RestToolbox.DoPost(‘%s/modalities/OrthancVM/store’ % URL, instances)