Difference between addObjects and addPathObjects?

Hello,
I have a list of images in a project for which I need to read annotations from an external source and render. When I do this for a single image using static method addObjects, it works.
However when I try to run this over all images in the project, using PathObjectHeirarchy from an image entry, I’m unable to see the annotations. What could be wrong?

Code that works:
def imageData = getCurrentImageData()

// finally add to the image using static method
addObjects(annotationList)

Code that doesnt seem to work:
for (entry in project.getImageList()){

imageData = entry.readImageData();
imageData.getHierarchy().addPathObjects(annotationList);
}

The static method addObjects just calls PathObjectHiearchy.addPathObjects for the image currently open in the viewer.

When you loop through the entries, the viewer is entirely ignored (including any unsaved changes for the current image).

To see changes from your script, your loop will need need to save the changes you’ve made, and you’ll have to (re)load the image in the viewer. This means your loop will need to include something like this:

for (entry in project.getImageList()){
    imageData = entry.readImageData()
    …
    imageData.getHierarchy().addPathObjects(annotationList)
    …
    // Make sure to save!
    entry.saveImageData(imageData)
}
2 Likes