Hello Pete,
thank you for your post. My understanding of the language is not good enough to finish it by myself.
We have the above two parts of the script now. I tried to fuse them but I dont know how to build a loop and how to go further after selected ->:
import qupath.lib.roi.*
import qupath.lib.objects.*
def selectedObjects = getSelectedObjects();
def areaAnnotations = getAnnotationObjects().findAll {it.getROI() instanceof AreaROI};
areaAnnotations.each { selected ->
//second part here. Above "Selected" is used but not defined yet, right?
def selected = getSelectedObject();
if (!(selected.getROI() instanceof AreaROI)) {
print 'Selected object does not have an AreaROI!'
return
};
// Try to do split, and ensure holes are taken into consideration
def polygons = PathROIToolsAwt.splitAreaToPolygons(selected.getROI())
def newPolygons = polygons[1].collect {
updated = it
for (hole in polygons[0])
updated = PathROIToolsAwt.combineROIs(updated, hole, PathROIToolsAwt.CombineOp.SUBTRACT)
return updated
};
// Remove original annotation, add new ones
annotations = newPolygons.collect {new PathAnnotationObject(it)};
resetSelection();
removeObject(selected, true);
addObjects(annotations);
Best and thanks a lot!
David