Note that there are some explanatory texts on larger screens.

plurals
  1. POImageJ GenericDialog - String containing backslashes is not escaped when recording macro
    primarykey
    data
    text
    <p>I am developing an ImageJ plugin and I ran into this problem. </p> <p>I am using <code>GenericDialog</code> with a text field so the user can input a file system path to a file. On windows, the path contains backslashes. When I am recording a macro for this plugin, I get this result:</p> <pre><code>run("Example ", "path=C:\results.txt"); </code></pre> <p>The backslash is not escaped and when i try to run the recorded command, the backslash is interpreted as an escape character and obviously, the file can't be found.</p> <p>Is there a way to use <code>GenericDialog</code> in a way that it correctly records text field containing backslashes? Or I can't use <code>GenericDialog</code> and have to implement macro recording functionality myself?</p> <p>EDIT: example plugin with the problem:</p> <pre><code>import ij.IJ; import ij.ImagePlus; import ij.gui.GenericDialog; import ij.plugin.filter.ExtendedPlugInFilter; import ij.plugin.filter.PlugInFilter; import ij.plugin.filter.PlugInFilterRunner; import ij.process.ImageProcessor; public class Example_ implements ExtendedPlugInFilter { public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { GenericDialog gd = new GenericDialog("Example"); gd.addStringField("path", "C:\\results.txt"); gd.showDialog(); String path = gd.getNextString(); IJ.showMessage("path = " + path); return PlugInFilter.DONE; } public void setNPasses(int nPasses) { } public int setup(String arg, ImagePlus imp) { return PlugInFilter.NO_IMAGE_REQUIRED; } public void run(ImageProcessor ip) { } } </code></pre> <p>When i run the macro recorded from this plugin, it shows "path = C:esults.txt".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload