ZBrushCentral

Set switch state without executing it.

I want store some user preferences between zbrush sessions and load switches state after startup.
I have memblock loaded/created at start, it contains information about pressed switches but I don’t know how to change their sates without executing commands. :wink:
There is command for that?

Unless I’m mistaken; As menus are context sensitive, you’d have to load a .ztl of the appropriate type for it/them to show.

Yea there isn’t a way that I know of.

How I get around this is by making a “empty” switch near the button and use it like a on/off notice. You can see a great example of this in the Document>ZappLink Properties where you store the views. When you press one of those buttons a switch behind the button becomes enabled to notify the user if it’s on or off.

You can do it by checking that the switch is actually being pressed by the user and only execute its code when that happens:


[ISwitch,"ZPlugin:Misc Utilities:Test 1",0,"Set the state of Test 2",
    [ISet,"ZPlugin:Misc Utilities:Test 2",1],[ISet,"ZPlugin:Misc Utilities:Test 2",0]
,,0.5]

[ISwitch,"ZPlugin:Misc Utilities:Test 2",0,"Show a note",
    [If,[IGet,Preferences:Utilities:View Window Id]==[IGetID,0],
      [Note,"Test 2 switch is on"]
    ]
    ,
    [If,[IGet,Preferences:Utilities:View Window Id]==[IGetID,0],
      [Note,"Test 2 switch is off"]
    ]
,,0.5]

//make sure switches remain enabled
[IEnable,"ZPlugin:Misc Utilities:Test 1"]
[IEnable,"ZPlugin:Misc Utilities:Test 2"]

Notes:

  • In the [IGetID,0] code above, the zero is a short way of specifying ‘this interface item’, instead of putting the actual button path.
  • If the user assigns a hotkey to the switch then the code would fail.

Here’s code that takes care of the possibility of the user assigning a hotkey. It also demonstrates how you can set the switch states on plugin reload (after another plugin has been used), so that the user only has to click the switch once to get it to respond. The memblock could be created from a file on disk so that the switch states could be saved between sessions but I’ve omitted that for simplicity.

//check for a memblock
[If,[MemGetSize,MC_SwitchTest],
  //do nothing, we have the settings memblock
  ,	
		[MVarDef,MC_SwitchTest,2]//create memblock for number of switches
		//initialize switch states (both off)
		[MVarSet,MC_SwitchTest,0,0]//"ZPlugin:Misc Utilities:Test 1"      
		[MVarSet,MC_SwitchTest,1,0]//"ZPlugin:Misc Utilities:Test 2"
]

[RoutineDef,Startup,//sets switches to respond first time when user clicks
	[VarDef,winID,0]
	[VarDef,idx,100]
	[IFreeze,
  	[If,[IExists,"ZPlugin:Misc Utilities:Test 2"],//only execute code when plugin is on interface
  		[VarSet,winID,[IGet,Preferences:Utilities:View Window Id]]
  		[Loop,1,	
  		  [If,winID==[IGetID,"ZPlugin:Misc Utilities:Test 1"],[VarSet,idx,0][LoopExit]]
  		  [If,winID==[IGetID,"ZPlugin:Misc Utilities:Test 2"],[VarSet,idx,1][LoopExit]]
  	  ]//end loop
  	  [If,idx != 100,
    		[If,[MVarGet,MC_SwitchTest,idx]==0,
    		 	[MVarSet,MC_SwitchTest,idx,1]
    		,  
    		 	[MVarSet,MC_SwitchTest,idx,0]
    		]	
    	]
    ]//end if
  ]//end freeze	
]

[RoutineCall,Startup]

//Misc Utilities
[ISubPalette,"ZPlugin:Misc Utilities"]


[ISwitch,"ZPlugin:Misc Utilities:Test 1",[MVarGet,MC_SwitchTest,0],"Set the state of Test 2",
    [MVarSet,MC_SwitchTest,0,1]//record switch state   
    [ISet,"ZPlugin:Misc Utilities:Test 2",1]
    ,
    [MVarSet,MC_SwitchTest,0,0]//record switch state   
    [ISet,"ZPlugin:Misc Utilities:Test 2",0]
,,0.5]

[ISwitch,"ZPlugin:Misc Utilities:Test 2",[MVarGet,MC_SwitchTest,1],"test",
    [MVarSet,MC_SwitchTest,1,1]//record switch state
    [If,(([IGet,Preferences:Utilities:View Window Id]==[IGetID,0])||
      ([IGet,Preferences:Utilities:View Keyboard Status]==[IGetHotkey,0])),
      [IKeyPress,1]//reset View Keyboard Status (1 is not a keyboard character)
      [Note,"Test 2 switch is on"]
    ]
    ,
    [MVarSet,MC_SwitchTest,1,0]//record switch state
    [If,(([IGet,Preferences:Utilities:View Window Id]==[IGetID,0])||
      ([IGet,Preferences:Utilities:View Keyboard Status]==[IGetHotkey,0])),
      [IKeyPress,1]//reset View Keyboard Status (1 is not a keyboard character)
      [Note,"Test 2 switch is off"]
    ]
,,0.5]

//make sure switches remain enabled
[IEnable,"ZPlugin:Misc Utilities:Test 1"]
[IEnable,"ZPlugin:Misc Utilities:Test 2"]

Ah very cool Marcus! You never never stop surprising me with little tidbits.