ZBrushCentral

Can't make a press state for custom button

Hi everyone,
I sorry because probably that’s a very dumb question but I can’t figure out how to make a custom button with press state, like this:

I’m trying to make a shorter version of ‘Enable Spotlight Projection’ button and I’ve tried:

[IButton,“ZPlugin:My Buttons:Test”,“Enable Spotlight Projection”,
[IShowActions,0][If,[IGet,Brush:Samples:Spotlight Projection] == 0,

[IPress,ZPlugin:My Buttons:Test]

[IPress,Brush:Samples:Spotlight Projection]

,//else set to zero

[IUnPress,ZPlugin:My Buttons:Test]

[IUnPress,Brush:Samples:Spotlight Projection]

]
]

and

[IButton,“ZPlugin:My Buttons:Test”,“Enable Spotlight Projection”,
[IShowActions,0][If,[IGet,Brush:Samples:Spotlight Projection] == 0,

[IToggle,ZPlugin:My Buttons:Test]

[IPress,Brush:Samples:Spotlight Projection]

,//else set to zero

[IToggle,ZPlugin:My Buttons:Test]

[IUnPress,Brush:Samples:Spotlight Projection]

]
]

but is stays in the same unpressed state. Can you please point me what I’m doing wrong?

Many thanks!

Attachments

Screenshot_5_29_14_11_51_AM.jpg

You need to use an ISwitch instead of an IButton. That will appear orange when turned on.

But note that your custom switch will not automatically reflect the state of the original ‘Enable Spotlight Projection’ switch. In other words, you will need to press your switch to be sure that its state matches the original.

Thanks, Marcus! While my question was on moderation I found out about ISwitch: at first I didn’t notice that those pressing buttons were actually different from IButtons. The only thing I can’t get about them now is about size: the reference says that I need to put size in the end:
[ISwitch, Switch name , Initial state, Popup info Text, Commands when is pressed , Commands when unpressed, Initially Disabled, Switch width in pixels]

I made a switch like that:
[ISwitch, “ZPlugin:My Buttons:test1”, 1, “Enable Spotlight Projection”,[IPress,Brush:Samples:Spotlight Projection],
[IUnPress,Brush:Samples:Spotlight Projection],
0, 35
]

But it locks after every press:
Screenshot_5_29_14_5_55_PM.jpg

If I take away the line “0, 35” everything works. I’m not sure what’s going on, am I missing something again?

It looks like the button width is not working. Not sure why, but you can use a decimal to represent ‘palette width’ (1 = wholewidth, 0.5 = half, etc.). Also, you need to put [IEnable] outside the switch code to make sure the switch doesn’t become disabled. Here’s how:

[ISwitch, “ZPlugin:My Buttons:test1”, 1, “Enable Spotlight Projection”,
//code for switch ON
[If,[IGet,Brush:Samples:Spotlight Projection]==1,
[ISet,“ZPlugin:My Buttons:test1”,1]
,
[IPress,Brush:Samples:Spotlight Projection]
]
,//code for switch OFF
[If,[IGet,Brush:Samples:Spotlight Projection]==1,
[IUnPress,Brush:Samples:Spotlight Projection]
,
[ISet,“ZPlugin:My Buttons:test1”,0]
]
,0,.5]

[IEnable,“ZPlugin:My Buttons:test1”]

I have also added some code which tests your switch state against the Spotlight Projection switch. This means that you only have to press your switch once to be sure that its state matches the other.

HTH,

Thank you very much, Marcus, I started to understand how it works. Cheers!

You’re welcome. I realised that my extra code (for testing the switch states) was unnecessary in this instance. I had been thinking of problems I had had with a more complicated set up!

Funny fact: this switch locks after one press too. But if I set the size with VarSet it works fine! Thanks again :slight_smile:

That is very odd. Can I see your complete code?

I think I got it: for one switch I didn’t put IEnable and doc says “for zplugins, it is best to use the [IEnable] command for each switch to make sure switches do not become disabled” — that’s why my switch was grayed out after click. My mistake, sorry!

No problem, so long as you have it working.