QuPath Setting PathObject Names Not Updating

I want to export images of positive cell detections along with their data. I also want to give each cell and annotation a unique UUID. I do not want the ID to change each time I run my script, so I set the UUID as the name of the cell (or annotation) and then when I run QuPath again, it only assigns a new UUID if getName() is null:

def GetUniqueName(pathObject){
    if (pathObject.getName() == null){
        def verCode = UUID.randomUUID().toString()
    return pathObject.getName()

However, each time I run the code, new versions are created with new names.

When I save the data sometimes the names update, sometimes they just say “PathCellObject”. In addition, when I go back to QuPath GUI, I see a similar problem.

This is how I save:
saveMeasurements(imageData, PathDetectionObject.class, path);

Is pathObject.setName(verCode) not really setting the name? help!

Could you include more of the rest of the script? That is how you set names, so I do not see a problem there.

If you are running a script that includes a step that generates cells, I would expect new cells to be generated without UUID. But without knowing what is in the rest of the script or what you are running multiple times, it is hard to say what is going on.

If the cell name is PathCellObject, then the name is not being updated.

Edited whole script to be code.

    if (it.getName() == null){
        def verCode = UUID.randomUUID().toString()

The above code changed the name of every cell for me. This would NOT change the names of any objects I exported the measurements for until I saved the data, though. Unsaved changes are not exported.

Generally, I just count the objects, though.

    if (it.getName() == null){
        def verCode = (x+1).toString()

Thank you for your help. I do think it has something to do with saving the data.

do you need to save the data after you do setName? Is there a way to do it through the script, rather than through the GUI?

If you Run for Project, the data file is saved. If you Run, the results are temporary until you save. You can save the imageData, but I forget the exact command at the moment. It is somewhere on the forum.

oooooh I think I was just doing Run. Will try Run for project.

Nope - still have this problem. Weirdly only for the second image on my list (not the first). Will check forum about saving imageData as you suggested.

Yup that was the problem. All I needed to add was


and to run for project

Thank you so much for your help! :slight_smile:

1 Like

Run for Project is intended for running a script across a project, so would save any changes to each individual image in turn. If you are not using a standard script structure then you do need to find other ways to save.