Paintbrush tool in macro

Tags: #<Tag:0x00007fa3050f6658>



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.


Shortcuts: Paintbrush and color selector

Good day Melch,

just have a look at the ImageJ-documents especially the "Built-in Macro Functions"
and you may find this:

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.




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



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:


Good day Melch,

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

Paintbrush Tool


setTool( "Paintbrush Tool" );

works for me.




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!


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?


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:

Good luck



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");


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.




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




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!



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.


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:


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


(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.)


In case it matters: Here is my 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.




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:


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…



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:


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?



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

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