Hi Philippe,

it won't work you replace the slashes with backslashes (a Windows issue): Then the JavaScript code has a \" as a delimiter, which means that the quote gets escaped and won't terminate the String any more.

I guess that current versions of Windows can also handle normal slashes as delimiters in paths, so you don't need to replace the slashes. Otherwise you would have to replace the single normal slashes be double backslashes.

Concerning
> Cannot set property "directory" of null in <eval> at line number 1

This happens if the image has not FileInfo because it was created with "new image". Thus, if imp.getOriginalFileInfo() returns null, you have to use imp.getFileInfo() instead. This creates a new FileInfo object.


Michael
________________________________________________________________
On 05.09.24 23:04, CARL Philippe (LBP) wrote:
Dear Michael,
I thank you very much for your answer.
Being as well part of the "people who don't like escaping inner quotes with the 
backslacsh character" I quite like your second proposed solution, which I discovered 
with your mail. So thanks a lot!
Nevertheless, with the following code:

        newImage("myPicture", "RGB ramp", 256, 256, 1);
        filePath = "/home/schmid/tmp/";
        filePath = filePath.replace("/", File.separator);
        dummy1 = eval('script', 'IJ.getImage().getOriginalFileInfo().directory = "'+ 
filePath + '";');
        dummy2 = eval("script", 
"IJ.log(IJ.getImage().getOriginalFileInfo().directory);");
        run("Show Info...");

I get the following error messages:

<eval>:1:764 Missing close quote
load("nashorn:mozilla_compat.js");importPackage(Packages.ij);importPackage(Packages.ij.gui);importPackage(Packages.ij.process);importPackage(Packages.ij.measure);importPackage(Packages.ij.util);importPackage(Packages.ij.macro);importPackage(Packages.ij.plugin);importPackage(Packages.ij.io);importPackage(Packages.ij.text);importPackage(Packages.ij.plugin.filter);importPackage(Packages.ij.plugin.frame);importPackage(Packages.ij.plugin.tool);importPackage(java.lang);importPackage(java.awt);importPackage(java.awt.image);importPackage(java.awt.geom);importPackage(java.awt.event);importPackage(java.util);importPackage(java.io);function
 print(s) {IJ.log(s);};function getArgument() {return 
"";};IJ.getImage().getOriginalFileInfo().directory = "\home\schmid\tmp\";
                                                                                      
                                                                                      
                                                                                      
                                                                                      
                                                                                      
                                                                                      
                                                                                      
                                                                                      
                                                                             ^ in 
<eval> at line number 1 at column number 764
TypeError: Cannot get property "directory" of null in <eval> at line number 1

and in the case I get rid of the "filePath = filePath.replace("/", 
File.separator);" line I get the following errors:

TypeError: Cannot set property "directory" of null in <eval> at line number 1
TypeError: Cannot get property "directory" of null in <eval> at line number 1

Should I understand that this is a Windows specific issue ?

Kindest regards,

Philippe

----- Mail original -----
De: "Michael Schmid" <[email protected]>
À: "imagej" <[email protected]>
Envoyé: Jeudi 5 Septembre 2024 17:18:09
Objet: File.directory parameter on concatened picture

Hi Philippe,

hmm, I think you got the solution already, it works for me (at least I
can see the directory in the image Info:

filePath="/home/schmid/tmp/";
dummy=eval("script", "IJ.getImage().getOriginalFileInfo().directory =
\"" + filePath + "\";");

People who don't like escaping inner quotes with the backslacsh
character could also write
dummy=eval('script', 'IJ.getImage().getOriginalFileInfo().directory = "'
+ filePath + '";');

(I assigned the output of "eval" to a dummy variable; otherwise the
directory is written to the Log window.)

Maybe your directory path was missing the trailing slash?


Michael
________________________________________________________________
On 05.09.24 16:59, CARL Philippe (LBP) wrote:
Dear all,
Within a macro I would like to set the File.directory parameter of a picture obtained 
through a Image>Stacks>Tools>Concatenete... process (given that this parameter 
is read by a plugin I want to apply on the concatened picture).
Given that filePath is the String containing the path I would like to set, I 
tried to use the following macro code (without any success):
        eval("script", "IJ.getImage().getOriginalFileInfo().directory = \"" + filePath + 
"\";");
I guess I'm not too far from the solution, but can't reach it.
I thank you very much in advance for your help on this.
My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 41

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Reply via email to