ZBrushCentral

Simple macro that runs on active subtools

Hi people, need a little help here.

I’m trying to write a script that runs across all the visible subtools but i keep gettiing odd behaviors that are not what i wanted to happen, it’s a mess…

I’ve tried following some examples but i keep getting nowhere. Does somebody happen to know the basic structure of a loop macro on active subtools in zbrush2020?

Here’s my super basic script i’d like to run in a loop

//ZBRUSH MACRO - Recorded in ZBrush version 2020
[IButton,???,"Press to run this macro. Macros can be aborted by pressing the ëescí key.",
[IShowActions,0]
[IConfig,2020]
[ISet,Tool:Masking:Range,80]
[ISet,Tool:Masking:Falloff,100]
[IPress,Tool:Masking:Mask By Smoothness]
[IColorSet,0,255,255]
[IPress,Color:FillObject]
[IPress,Tool:Masking:Inverse]
[IColorSet,255,0,0]
[IPress,Color:FillObject]
]

This sounds like a very common function. I have been searching for a way to loop through visible subtools to run a macro or script. I’m not a coder, but can learn scripting by looking at examples. I would like to see if anyone has an answer for this too.
Thank you!!!

Check this answer by Marcus Civis,

Zbrush 2019 - run on visible subtools script - #6 by marcus_civis

I reformated the code. You will just have to put your macro code in the Doit routine :

[RoutineDef, SubToolIsVisible,

    [VarSet, isVisible, 0]

    [VarSet,st,[SubToolGetStatus,id]]

    [VarSet,fInd,[SubToolGetFolderIndex,id]]

    [If,(fInd > -1),//it's in a folder

        [VarSet,stFld,[SubToolGetStatus,fInd]]//get folder visibility

        [If,([Val,stFld]&0x2 == 0x2)&&([Val,st]&0x1 == 0x1),

            [VarSet,isVisible,1]

        ]

        ,//else no folder

    [If,([Val,st]&0x1 == 0x1),

     [VarSet,isVisible,1] ]

    ]

     ,isVisible,id

]

[RoutineDef, DoIt,

  [IPress,"Color:Fill Object"]

]

[IButton,"Do Visible","Run routine on Visible subtools",

[VarSet,activST,[SubToolGetActiveIndex]]//store active subtool

[VarSet,isVis,0]

[Loop,[SubToolGetCount],//loop through all subtools

[SubToolSelect,[Val,n]]

[RoutineCall,SubToolIsVisible,isVis,[Val,n]] //check visibility

[If,(isVis), //code for visible subtool

    [Note,[StrMerge,"SubTool ",[Val,n]," is Visible"]]

    [RoutineCall,DoIt]

    ,//else

    [Note,[StrMerge,"SubTool ",[Val,n]," is Hidden"]]

]

,n]

//end loop

[SubToolSelect,activST]//reselect active subtool

]//end button

Very cool!
Thank you. I get a dialog after every time the loop runs. Is there any way to avoid it?
Screen Shot 2023-03-07 at 01.42.20 PM

comment the following line by putting // before it or delete it if you want
or replace the instruction Note by Notebar…

Thank you, so much!

My loop does a “Fix Mesh” which throws up the following note:
Screen Shot 2023-03-09 at 12.36.09 PM
Is there any way to dismiss this automatically?
it just requires a click anywhere to make it go away, but I have to click each time!!
Click…
Click…
Click…
Click…
Click…
Click…
Click…
Click…
ect…