Re: Different behavior of plugin called from macro

Posted by Jon Harman-3 on
URL: http://imagej.273.s1.nabble.com/Different-behavior-of-plugin-called-from-macro-tp5014701p5014709.html

Hi,
After changing all my IJ.Run to use the ImagePlus directly, my problems
have disappeared.

Thanks
Jon

On 10/21/2015 10:27 AM, Michael Schmid wrote:

> Hi Jon,
>
> when selecting an image, use the WindowManager.setCurrentWindow function, instead of bringing an image to the foreground (which depends on the gui).
> Even better, it should be possible to address the ImagePlus directly:
>
>    IJ.run(imp, "Crop", null);
>
> where imp is your ImagePlus (named 'trans'?)
>
> Michael
> ________________________________________________________________
> On Oct 21, 2015, at 19:12, Jon Harman wrote:
>
>> Hi,
>> I have a plugin that as part of a long sequence of image manipulations crops an image.  This works fine when run from the plugins menu.  When I run the plugin from a macro the crop fails, saying an area selection is required.  When it fails it displays the image with a rectangle ROI which is the wrong size.
>> The plugin is then permanently broken until I restart ImageJ.  Then it works fine again.
>>
>> This is a mystery to me.  Hope someone can help.  my code is:
>>
>> Polygon corners = new Polygon();
>> for(int i = 0; i < 4; i++) corners.addPoint(cor[i].x,cor[i].y);
>> corners.addPoint(cor[0].x, cor[0].y);// close the polygon
>> PolygonRoi corroi = new PolygonRoi(corners, Roi.POLYGON);
>>
>> iw = trans.getWindow();
>> iw.toFront();
>> trans.setRoi(corroi);
>> trans.show();
>> IJ.run("Crop");
>>
>> Jon
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html