Re: Using setColor without an open image

Posted by Wayne Rasband-2 on
URL: http://imagej.273.s1.nabble.com/Re-Using-setColor-without-an-open-image-tp5021956p5021959.html

> On Apr 1, 2019, at 8:15 AM, Stein Rørvik <[hidden email]> wrote:
>
> I agree that the behaviour should not be altered if the setting is per image.
> But I do not get the same behaviour, for me the setColor is global.  
>
> Also, it seems setLineWidth is reset when changing images,
> but it is not remembered per image.

With the latest daily build (1.52o13), the setColor() and setLineWidth() settings are both global.

Here is an example:

  close("*");
  setColor("red");
  setLineWidth(40);
  newImage("Untitled", "rgb black", 507, 446, 1);
  drawLine(0,0,507,446);
  run("Leaf (36K)");
  drawLine(0,0,507,446);
  selectImage(1);
  drawLine(507,0,0,446);
  selectImage(2);
  drawLine(507,0,0,446);
  run("Tile”);

-wayne


> Test macro:
> ------------------------------
> run("Close All");
> run("Clown (14K)");
> run("Clown (14K)");
>
> selectImage(1);
> setColor("yellow");
> setLineWidth(3);
> drawLine(100, 50, 200, 50);
>
> selectImage(2);
> setColor("cyan");
> setLineWidth(6);
> drawLine(100, 50, 200, 50);
>
> selectImage(1);
> drawLine(100, 100, 200, 100);
>
> selectImage(2);
> drawLine(100, 100, 200, 100);
>
> run("Tile");
> ------------------------------
>
> Stein
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
> Sent: 31. mars 2019 18:26
> To: [hidden email]
> Subject: Re: Using setColor without an open image
>
>> On Mar 30, 2019, at 2:56 PM, Stein Rørvik <[hidden email]> wrote:
>>
>> In a macro, you can use the functions
>>
>>                setFont(...
>>                setJustification(...
>>                setForegroundColor(...
>>                setBackgroundColor(...
>>
>> among others without an open image.
>>
>> But the
>>
>>                setColor(...
>>
>> function gives an error message without an open image.
>>
>> Same applies to
>>
>>                setLineWidth(...
>>
>> Can these two restrictions be removed
>
> I would prefer to not remove these restrictions. The color set by setColor() and line width set by setLineWidth() are associated with an image, so they are reset when you open a new image. Making them global would likely break some existing macros.
>
> -wayne
>
>
>> It often makes sense to put such initialization functions at the start of a macro when no image might have been opened or created yet.
>>
>> Besides, setColor and setLineWidth are not specific to the active image but a global setting as far as I can see.
>>
>> I tested the other set.. functions without images and they work as expected by giving missing image error message only when needed; when the settings are specific to one image.
>>
>> Stein

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