ZBrushCentral

Button Toggle on/off help

I notice many people with plugins that have a on/off toggle like with zbrush smt for subdividing.
How can I create a similar button? :frowning:

I found this code

[ISubPalette,ZPlugin:ProxyTest1,0,0,0,0]
[IConfig,4.31]
[IShowActions, 0]

[ISwitch, ā€œZPlugin:ProxyTest1:TopoMaskā€ ,
[IGet, Brush:Auto Masking:Topological],
ā€œTopo Maskā€,
[ISet, Brush:Auto Masking:Topological, 1],
[ISet, Brush:Auto Masking:Topological, 0],
0,
.5]
[IEnable,ā€œZPlugin:ProxyTest1:TopoMaskā€]

But the first time i click it it does nothing, have to click twice to get it going how can i fix that bug?

The problem is because the first click loads the plugin and the switch state is set to reflect the state of the Topological button. If the states are reversed then the button will work first time:

[ISubPalette,ZPlugin:ProxyTest1,0,0,0,0]
[IConfig,4.31]
[IShowActions, 0]

[VarDef,startupState,0]

[RoutineDef,Startup,
[If,[IExists,ā€œZPlugin:ProxyTest1:TopoMaskā€],

[VarSet,winID,[IGet,Preferences:Utilities:View Window Id]]

[If,[IGet, Brush:Auto Masking:Topological]==1,

[VarSet,startupState,0]

,

[VarSet,startupState,1]

]

]
]

[RoutineCall,Startup]

[ISwitch, ā€œZPlugin:ProxyTest1:TopoMaskā€ ,
startupState,
ā€œTopo Maskā€,
[ISet, Brush:Auto Masking:Topological, 1],
[ISet, Brush:Auto Masking:Topological, 0],
0,
.5]

[IEnable,ā€œZPlugin:ProxyTest1:TopoMaskā€]

Note that if your plugin had more than one switch then code would be necessary to find which switch was being pressed.

2 Likes

Thanks this is a great!

I realise I put in some code thatā€™s not needed in this case - where the winID variable is set. Thatā€™s how you can tell which button is clicked if you have more than one. Youā€™d then compare the winID with the numerical ID for the button (using [IGetID]). When it returns true, thatā€™s the button the user has clicked.