ZBrushCentral

Question: How to make a toggle button?

So I know very little about scripting but I made a couple macros. One to turn Colorize “ON” for all subtools and another to turn Colorize “OFF” for all subtools. I was wondering if there was a way to just make it a toggle so I could just have one button? Attached is the macro.

Also, I was wondering if that toggle could be used for slider values? For example I wanted to make a toggle for the brush setting “Automask by Polygroups.” It’s is a slider from 0 to 100. The button would toggle the value between 0 and 100.

All you need to do is put in a test so that if the button or slider is in one state then your macro sets the other state. You use the [If statement like this:


[If,[IGet,Tool:Polypaint:Colorize] == 1,//the button will return 1 if it's on
[IUnPress,Tool:Polypaint:Colorize]
,//else it's off so turn it on	
[IPress,Tool:Polypaint:Colorize]
]

and for the brush masking


[If,[IGet,Brush:Auto Masking:Mask By Polygroups] == 0,
[ISet,Brush:Auto Masking:Mask By Polygroups,100]
,//else set to zero
[ISet,Brush:Auto Masking:Mask By Polygroups,0]
]

Note that the brush masking toggle will turn off if the slider is set to any value above 0.

HTH,

Man this is awesome. The colorize toggle worked perfectly! You made me very happy Marcus.

I tried the brush masking code but it didn’t seem to work. Is there something else I have to add to it?

I’m sorry, I cut and pasted the code and managed to introduce a couple of extra brackets. Try again, I’ve corrected it. If it still doesn’t work, post your macro and I’ll take a look.

Yea I wasn’t able to get it to work.

I only posted a code snippet - you need to have a button for the macro to appear (and work). Try this version.

Ah right, Thank you so much! This is really awesome.

Is it possible to have zbrush remember the toggle state so that when you restart zbrush the toggle button is always on or off?

Thanks

Yes, but you have to be careful. The macro (or plugin) sets the state on start up having read the value from a file. If you try to set an interface item that isn’t present when ZBrush launches then you could get an error (for example, the activate symmetry button which only becomes available when a 3D tool is selected).

Anyhow, the attached macro shows the basic idea.

Holy crap that is amazingly awesome! It works perfectly! Thank you so much Marcus!:D:D:D

Eric,

Here’s another way to do toggles which may interest you:

http://www.zbrushcentral.com/showpost.php?p=871353&postcount=52

I wish I understood any of the stuff above.