Hi,
I'm trying to open and view files with ImageJ from within a VB excel macro via the command line. I've modified the 'analyze' demo plugin with some success (below). It works unless there is a space in the file path or name. Is there a trick to this? I've played with square brackets with no luck. Also, I'd like the use the existing ImageJ if it's open. Is this possible? It would be nice if the command dialog closed, but not the ImageJ window. Here is a snippet from excel where I'm putting the command line string together: pluginTxt = "jre\bin\java -Dplugins.dir=plugins -cp ij.jar;. openfromexcel " CmdLine = pluginTxt & Range("a1").Value & "\" & Range("A" + Trim(currentrow)).Value Where cell A1 in excel is the folder and A'n' the filename. Any advice welcome. Thanks, Toby import ij.plugin.*; import java.awt.*; import java.io.*; import ij.*; import ij.io.*; import ij.process.*; import ij.gui.*; import ij.measure.*; /** This is an example that shows how to write a command line utility that uses ImageJ as a library. Use the "Compile and Run" command to compile and test, then run from the command line. It requires ImageJ 1.29v or later. */ public class openfromexcel implements PlugIn { public void run(String arg) { OpenDialog od = new OpenDialog("Open...", ""); if (od.getFileName()==null) return; String dir = od.getDirectory(); if (dir==null) return; String name = od.getFileName(); process(dir+name); } void process(String path) { if (IJ.versionLessThan("1.33b")) return; IJ.log("opening "+path); IJ.run("Bio-Formats Importer (windowless)", "open=[" + path + "]"); } public static void main(String args[]) { if (args.length<1) IJ.log("usage: openfromexcel image"); else { new ImageJ(); // open the ImageJ window to see images and results new openfromexcel().process(args[0]); // System.exit(0); } } } Tony J. Collins, Ph.D. McMaster Biophotonics Facility Dept. Biochemistry and Biomedical Sciences HSC 4H21A McMaster University, Hamilton, ON, L8N 3Z5 (905) 525 9140 x28812(off.)/x26488(lab) [hidden email] www.macbiophotonics.ca |
Tony -
When I've dealt with filenames from VB, I've needed to add quotes to the filename. You can either use 4 quotes to insert the quote marks or the Chr command (but I forget which ascii code goes with quote): CmdLine = pluginTxt & """" & Range("a1").Value & "\" & Range("A" + Trim(currentrow)).Value & """" Good luck! Jeff Hanson Senior Imaging Analyst Eli Lilly and Company [hidden email] Tony Collins <[hidden email]> Sent by: ImageJ Interest Group <[hidden email]> 12/13/2007 01:20 PM Please respond to ImageJ Interest Group <[hidden email]> To [hidden email] cc Subject calling imagej from excel Hi, I'm trying to open and view files with ImageJ from within a VB excel macro via the command line. I've modified the 'analyze' demo plugin with some success (below). It works unless there is a space in the file path or name. Is there a trick to this? I've played with square brackets with no luck. Also, I'd like the use the existing ImageJ if it's open. Is this possible? It would be nice if the command dialog closed, but not the ImageJ window. Here is a snippet from excel where I'm putting the command line string together: pluginTxt = "jre\bin\java -Dplugins.dir=plugins -cp ij.jar;. openfromexcel " CmdLine = pluginTxt & Range("a1").Value & "\" & Range("A" + Trim(currentrow)).Value Where cell A1 in excel is the folder and A'n' the filename. Any advice welcome. Thanks, Toby import ij.plugin.*; import java.awt.*; import java.io.*; import ij.*; import ij.io.*; import ij.process.*; import ij.gui.*; import ij.measure.*; /** This is an example that shows how to write a command line utility that uses ImageJ as a library. Use the "Compile and Run" command to compile and test, then run from the command line. It requires ImageJ 1.29v or later. */ public class openfromexcel implements PlugIn { public void run(String arg) { OpenDialog od = new OpenDialog("Open...", ""); if (od.getFileName()==null) return; String dir = od.getDirectory(); if (dir==null) return; String name = od.getFileName(); process(dir+name); } void process(String path) { if (IJ.versionLessThan("1.33b")) return; IJ.log("opening "+path); IJ.run("Bio-Formats Importer (windowless)", "open=[" + path + "]"); } public static void main(String args[]) { if (args.length<1) IJ.log("usage: openfromexcel image"); else { new ImageJ(); // open the ImageJ window to see images and results new openfromexcel().process(args[0]); // System.exit(0); } } } Tony J. Collins, Ph.D. McMaster Biophotonics Facility Dept. Biochemistry and Biomedical Sciences HSC 4H21A McMaster University, Hamilton, ON, L8N 3Z5 (905) 525 9140 x28812(off.)/x26488(lab) [hidden email] www.macbiophotonics.ca |
Free forum by Nabble | Edit this page |