Last active
March 13, 2018 14:56
-
-
Save NicoKiaru/947544afeba881b4208a33a5ae6f3c0f to your computer and use it in GitHub Desktop.
How to launch a script before testing an IJ2 Command during development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scijava.command.Command; | |
import org.scijava.command.DynamicCommand; | |
import org.scijava.log.LogService; | |
import org.scijava.plugin.Parameter; | |
import org.scijava.plugin.Plugin; | |
import ij.ImagePlus; | |
import net.imagej.ImageJ; | |
@Plugin(type = Command.class, menuPath = "Plugins>MyCommand>Say Hello") | |
public class CmdTest extends DynamicCommand{ | |
@Parameter | |
private ImagePlus imp; | |
@Parameter | |
LogService ls; | |
@Override | |
public void run() { | |
ls.info("Hello from the CmdTest Command"); | |
ls.info("The image is called "+imp.getTitle()); | |
} | |
/** | |
* This main function serves for development purposes. | |
* @param args whatever, it's ignored | |
* @throws Exception | |
*/ | |
public static void main(final String... args) throws Exception { | |
// Creates an IJ instance | |
final ImageJ ij = new ImageJ(); | |
ij.ui().showUI(); | |
// Code of an IJ1 Macro | |
String ij1Macro = "print('Hello from an IJ1 Macro');\n"; | |
ij1Macro+= "run('Blobs (25K)');"; | |
// Executes the IJ1 Macro and waits to finish (get()) | |
ij.script().run("foo.ijm",ij1Macro, true).get(); | |
// Launch the command which requires an open image | |
ij.command().run(CmdTest.class, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment