Adding Unit to Filename

Hi!

I am trying to save my results with a custom filename. I figured out how to get filename from photo and replace “.tif” with “.csv”.
But my current challenge is using the data of unit. Because each SEM photo I use have different units (µm or nm). I manually enter this data while I set the scale but I do not know how I can get this info and use on filename part of my macro code.

My current macro code for it this:

//saving the file
name = getTitle;
            dotIndex = indexOf(name, ".tif");
            title = substring(name, 0, dotIndex); 
saveAs("Results", "/Users/macbook/Desktop/"+title+".csv");

At the end I need the filenames like that [title+um or nm]
Screenshot 2021-01-23 at 23.29.48

Can anybody help me on this?

Thanks a lot in advance!

Podi

@Podi
Maybe this?

 requires("1.32f");
newImage("Machin", "RGB white", 256, 256, 1);
//setTool("line");
makeLine(44, 185, 160, 187);
run("Set Scale...", "distance=116.0172 known=1 unit=mm");
   title = getTitle;
  getPixelSize(unit, pw, ph, pd);
  print("Title: " + title);
  print("Unit=",unit);
// saveAs( "C:/.....................your folder name................../"+title+"_"+unit+".png");

Reading this may interest you: getPixelSize(unit, pixelWidth, pixelHeight)
https://imagej.nih.gov/ij/developer/macro/functions.html#G

2 Likes

Hey @Mathew thanks for your comment.
I failed on that part getPixelSize(unit, pw, ph, pd);

Now my current code is like that and works as I wish,

name = getTitle;
            dotIndex = indexOf(name, ".tif");
            title = substring(name, 0, dotIndex); 
getPixelSize(unit, pw, ph, pd);
saveAs("Results", "/Users/macbook/Desktop/"+title"+"_"+unit+".csv");

Thanks lot!