Overlay overlay = imp.getOverlay();
if (overlay==null) {
IJ.error("Overlay required");
return;
}
RoiManager rm = RoiManager.getInstance();
if (rm==null) {
if (Macro.getOptions()!=null && Interpreter.isBatchMode())
rm = Interpreter.getBatchModeRoiManager();
if (rm==null) {
Frame frame = WindowManager.getFrame("ROI Manager");
if (frame==null)
IJ.run("ROI Manager...");
frame = WindowManager.getFrame("ROI Manager");
if (frame==null || !(frame instanceof RoiManager))
return;
rm = (RoiManager)frame;
}
}
if (overlay.size()>=4 && overlay.get(3).getPosition()!=0)
Prefs.showAllSliceOnly = true;
rm.runCommand("reset");
for (int i=0; i<overlay.size(); i++)
rm.add(imp, overlay.get(i), i);
rm.setEditMode(imp, true);
if (rm.getCount()==overlay.size())
imp.setOverlay(null);
}