ImageJ 中 运行 宏时出现未定义变量错误

Undefined variable error when running macro in ImageJ

我是 ImageJ 宏的新手,我想在斐济使用宏。宏的代码来自这个 source.

macro "MultiRoiMove Tool - C00cT0f16M" {
  if (RoiManager.selected<2) exit(); 
  indexes=split(call("ij.plugin.frame.RoiManager.getIndexesAsString"));
  roiManager("Combine");
  getCursorLoc(x, y, z, modifiers);
  Roi.getBounds(x0, y0, width, height);
  while(modifiers&16>0) {
    getCursorLoc(x1, y1, z, modifiers);
    Roi.move(x0+x1-x, y0+y1-y);
  }
  roiManager("select", indexes);
  roiManager("translate", x1-x, y1-y);
}

我已经下载了代码并将其保存为文本文件。我然后 运行 通过转到插件 > 宏 > 运行 宏。我使用的ImageJ版本是1.53j.

但是,当我 运行 宏时,出现以下错误:

我在 ImageJ forum 网上看到这个宏对其他人有效。我已经进行了一些调试并且知道我收到了错误,因为当我 运行 宏时代码没有进入 while 循环,所以 x1 没有返回值 getCursorLoc函数。

但我不知道如何让代码进入 while 循环。有谁知道我是否必须在 运行 启用宏之前单击特定内容?在我看来,当鼠标修饰符事件发生时,代码将进入 while 循环(因为 getCursorLoc 函数返回的修饰符参数是鼠标事件修饰符标志)。感谢任何帮助。

您需要 select ROI 管理器中您想要移动的 ROI。您可以单击第一个,然后按 cmd 并单击(在 Mac 上)以添加其他 ROI。然后宏将移动这些 ROI,但不会移动任何未select编辑的 ROI。

代码的 modifiers 部分接收正在按下的鼠标按钮,如果使用左键单击 (16) 并拖动,这将定义一个矩形,然后用于移动 ROI。

您应该选择插件 > Macros > 安装以将工具添加到工具栏。