Paintbrush tool in macro

imagej
macro

#1

Hi,

I have a question concerning the use of the Paintbrush tool.

I writing a macro (.imj) and I need to use this tool after a waitForUser(). I realy would like that this tool was selected in order to the user don’t have to find it. So, i’m looking for a command life setTool(“point”) to do this but I realy don’t find anythink…

If anyone have some idea.

Melch


Shortcuts: Paintbrush and color selector
#2

Good day Melch,

just have a look at the ImageJ-documents especially the "Built-in Macro Functions"
https://imagej.nih.gov/ij/developer/macro/functions.html
and you may find this:

setTool(name)
Switches to the specified tool, where name is “rectangle”, “roundrect”, “elliptical”, “brush”, “polygon”, “freehand”, “line”, “polyline”, “freeline”, “arrow”, “angle”, “point”, “multipoint”, “wand”, “text”, “zoom”, “hand” or “dropper”. Refer to the SetToolDemo, ToolShortcuts or ToolSwitcher, macros for examples. See also: IJ.getToolName.

Regards

Herbie


#3

yes I saw that. But there is not “name” for the Paintbrush tool…


#4

@Melch

There was an old ImageJ listserv topic on this as well…

If you print(toolID); after selecting the paintbrush - you’ll see it’s ID# is 19… so you can use the call setTool(19);.

eta :slight_smile:


#5

Good day Melch,

if you click on the “Paintbrush Tool” the status line below tells you the tool name, namely;

Paintbrush Tool

Threrefore

setTool( "Paintbrush Tool" );

works for me.

Regards

Herbie


#6

Thank you for your answers.

print(toolID); works fine. It gives me the number 17. So that’s nice!

setTool( “Paintbrush Tool” ); also works. Maybe it is a better solution as the tool ID can change. I was test that before but it didn’t work (I think I made a spelling mistake).

So my problem is now solved!


#7

In fact, just another point. Is there a way to change the width of the brush in the macro. I have try run(“Line Width…”, “line=40”); but it didn’t work…

Is there a way to open the option menu with a macro? or another solution?


#8

Good day Melch,

I think you’ve reached the limits of the very tool approach which is (start-up ) macro based.

This start-up macro in fact uses the draw routine of ImageJ for which you may set the line width. The same holds for the brush tool (do not confound with the Paintbrush Tool in question).

Perhaps you should switch to those, or you change the start-up macro of the Paintbrush Tool as proposed by Jerome Mutterer:
http://imagej.1557.x6.nabble.com/How-do-I-set-Pencil-Width-Brush-Width-or-Eraser-Width-from-within-a-Java-Plug-in-tp3682608.html

Good luck

Herbie


#9

The action of setting the brush width in the Paintbrush Tool Options is not being recorded by the macro recorder, but the following works for me in a macro:

run("Paintbrush Tool Options...", "brush=40");

#10

Good day Jan,

I get an

Unrecognized command: “Paintbrush Tool Options…”

alert and I still don’t think that there is another way to make it work as indicated above.

Regards

Herbie


#11

Strange, it successfully sets the brush width to 40 on my Fiji installation.

image

image


#12

Not here with plain ImageJ-1.51s on Mac with Java 6.
(But this doesn’t mean any problems for me…)

BTW the dialog looks different from mine where I have an additional color option and can check “Paint on overlay”. Funny!

Herbie


#13

In my current version this more extensive dialogue only appears for the Brush tool, not the Paintbrush tool. I cannot explain this disparity, maybe a Fiji developer can.

image

Note that I now updated to the latest IJ daily build and the macro from Jan still runs fine.


EDIT: I was able to reproduce your error @Herbie! Although it might not have been the same sequence of actions… And it appears to be a strange bug, or at least confusing.

If I select Drawing Tools in the More Tools menu I get:

image

Despite still seeing the paintbrush tool on the menu, but the options dialogue is slightly different (missing the (pixels)).

image

(We can split this topic if the discussion continues, so far the information is relevant to OP’s question, should he run into similar issues.)


#14

In case it matters: Here is my ScreenShot:

ScreenShot

Maybe the Paintbrush Tool has been converted to a plugin for ImageJ-2. At least mine is a startup macro that comes with ImageJ.

Regads

Herbie


#15

To conclude, we’re talking about three different flavors of this tool:

  1. the one shipping with Fiji in its standard toolbar setup (that you can activate any time by clicking on the >> menu and choosing Restore Startup Tools), where the brush width can be set like this:

    run("Paintbrush Tool Options...", "brush=40");
    
  2. the one from the ImageJ 1.x Startup Macros (that you can activate in Fiji by running >> StartupMacros), where setting the brush width programmatically apparently isn’t possible.

  3. the one in the Drawing Tools macro set (that you get by running >> Drawing Tools), where the brush width can be set like this (note the missing dots ...):

    run("Paintbrush Tool Options", "brush=40");
    

While I was referring to (1) in my post, @Herbie was using (2), and @Sverre was mentioning (1) and (3).

So, @Melch, I hope you’ll find a way that works fine for you :slight_smile:


#16

Ok so on my ImageJ 1.51j8, I have tried the third way.

Manualy I run the “Drawing Tools” (as indicated) and in a macro I try run(“Paintbrush Tool Options”, “brush=40”); and I got an error. I activated the Paintbrush tool with its ID (setTool(16);) and it works.

So may be I have to install Fiji to make it work!

Or I have to learn Java…


#17

@Melch

Try installing/using Fiji - if you don’t have a particular reason to use the ‘older’ ImageJ1.x version - try using Fiji. It is what we recommend to most users as it is simply a distribution of ImageJ that comes with a bunch of plugins bundled - ready for you to use out-of-the-box.

You can read more on the ‘flavors of ImageJ’ here.

Hope this helps!

eta :slight_smile:


#18

Hi guys,

I am writing a macro and i would like to set the paintbrush default size to 100 when the macro loads, is it possible to do this?

Thanks
Gavin


#19

It doesn’t get recorded unfortunately, but the following code should work (in Fiji):

run("Paintbrush Tool Options...", "brush=100");