Annotation import not working

Hi Forum,
I use Qupath 0.2.2. The script for batch import of annotation suddenly not working anymore. Could anyone suggest a solution. Many thanks in advance.

import qupath.lib.scripting.QP
import qupath.lib.geom.Point2
import qupath.lib.roi.PolygonROI
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.images.servers.ImageServer

//Aperio Image Scope displays images in a different orientation
def rotated = false

def server = QP.getCurrentImageData().getServer()
def h = server.getHeight()
def w = server.getWidth()

// need to add annotations to hierarchy so qupath sees them
def hierarchy = QP.getCurrentHierarchy()

//Prompt user for exported aperio image scope annotation file
def path = server.getURIs().getAt(0).getPath(); // HERE
path = path.substring(0, path.lastIndexOf(".")) + “.xml” // HERE
def file = new File(path)
def text = file.getText()

def list = new XmlSlurper().parseText(text)

list.Annotation.each {

it.Regions.Region.each { region ->

    def tmp_points_list = []

    region.Vertices.Vertex.each{ vertex ->

        if (rotated) {
            X = vertex.@Y.toDouble()
            Y = h - vertex.@X.toDouble()
        else {
            X = vertex.@X.toDouble()
            Y = vertex.@Y.toDouble()
        tmp_points_list.add(new Point2(X, Y))

    def roi = new PolygonROI(tmp_points_list)

    def annotation = new PathAnnotationObject(roi)

    hierarchy.addPathObject(annotation, false)


When was the last time it worked?

What is the source of the script? It’s not built-in to QuPath, or an official part of the software. It looks like it was written for v0.1.2.

What error message do you see?

1 Like

Hi Pete,
the script was from this thread:Importing batch annotations (xml) from a folder

the error message it gives:
ERROR: FileNotFoundException at line 23: ~ge46xaw\TUM-PC\all doc\Projects\Project_Tanja\mouse\ki67\image\2020-3_48-1_MCPT1.xml (Das System kann den angegebenen Pfad nicht finden)

ERROR: java.base/ Method)
java.base/ Source)
java.base/ Source)
org.codehaus.groovy.runtime.dgm$1040.invoke(Unknown Source)
java.base/ Source)
java.base/java.util.concurrent.Executors$ Source)
java.base/ Source)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.base/java.util.concurrent.ThreadPoolExecutor$ Source)
java.base/ Source)

It looks like the script can’t find your file.
At line 23, make sure that the path points to your actual file.
If I remember correctly, this is the reason why I added // HERE as a comment next to it.

1 Like

I went back to version 0.2.0 and use the same script without giving file path and it works. but for future, if i use later version (0.2.3), in that case, could you tell how to mention file path?

This seems to be the path that you give it: ~ge46xaw\TUM-PC\all doc\Projects\Project_Tanja\mouse\ki67\image\2020-3_48-1_MCPT1.xml
Is there a file at this location? Can you open it?

You might want to instead give it a full path manually? Just to be sure…

path = "your/full/path.xml"
1 Like