Here’s one way, using the not operator.
si = Application si.SetUserPref( "SI3D_CONSTRAINT_COMPENSATION_MODE", not si.GetUserPref("SI3D_CONSTRAINT_COMPENSATION_MODE") )
The “problem” with this approach is that you’re toggling between 0 and -1, not between 0 and 1 (when you click the CnsComp button in the UI, you set the pref to either 0 or 1). The -1 happens because not 0 is -1.
Application.LogMessage( True == 1 ) Application.LogMessage( False == 0 ) Application.LogMessage( not False == -1 ) # INFO : True # INFO : True # INFO : True
So here’s a couple of other ways to toggle the preference value:
si = Application si.SetUserPref( "SI3D_CONSTRAINT_COMPENSATION_MODE", 0 if si.GetUserPref("SI3D_CONSTRAINT_COMPENSATION_MODE") else 1 )
si = Application toggle = [1,0] si.SetUserPref( "SI3D_CONSTRAINT_COMPENSATION_MODE", toggle[si.GetUserPref("SI3D_CONSTRAINT_COMPENSATION_MODE")] )
BTW, you can also toggle with 1 – CurrentValue, that’s what I use to toggle booleans.