ZBrushCentral

Problems with function to enable/disable layers

The following simple script defines functions and a button to enable one to toggle the active layer between enabled and disabled states, just as one would do by pressing on it–in fact, that’s exactly what the script does.

However, for whatever reason, from the script this only works to enable a disabled layer; it doesn’t disable an enabled layer. If you try it, you’ll see the difference, and the various Note commands will give some debugging output.

I need to be able to do this somehow, as part of a much larger script. Anyone know what’s going on?

Thanks,
Ken

//ZScript

// Flag values for layer flags returned by IGetFlags.
// 0: Not Created
// 8: Disabled
// 9: Enabled
// 10: Disabled and the active layer
// 11: Enabled and the active layer

[RoutineDef, GetActiveLayer,
[Loop, 16,
[VarSet, layer, [StrMerge, "Layer:Layer ", [Val, n+1]]]
[VarSet, flags, [IGetFlags, layer]]
[If, (flags=10) || (flags=11),
[VarSet, result, layer]
[LoopExit]
]
, n]
, result]

[RoutineDef, Toggle2,
[VarDef, activeLayer, “”] [RoutineCall, GetActiveLayer, activeLayer]
[Note, [StrMerge, "TOGGLE: Toggling ", activeLayer]]
[IPress, activeLayer]
[Note, “TOGGLE: done”]
]

[ISubPalette, Document:Ortho]

[IButton, Document:Ortho:ToggleActive, “Toggle Active View”, [RoutineCall, Toggle2]]

[RoutineDef, Toggle2,
[VarDef, activeLayer, “”] [RoutineCall, GetActiveLayer, activeLayer]
[Note, [StrMerge, "TOGGLE: Toggling ", activeLayer]]
//Try pressing twice
[IPress, activeLayer]
[IPress, activeLayer]
[Note, “TOGGLE: done”]
]

I had the same problem with a script, pressing it twice seems to work. don’t ask me why.

If you use IClick instead of IPress it works fine.

First, to add a bit more knowledge about layer flags; each flag is a bit, and they have meanings as follows:

// LAYER BITS: (counting from bit 0 as the least significant bit.)
// Bit 0: 1 if enabled, 0 if not
// Bit 1: 1 if active layer, 0 if not
// Bit 2: ???
// Bit 3: 1 if created, 0 if not

Bit 2 is some sort of transient bit, which is apparently only used while my ZScript is executing. Don’t know what it’s for. In any case, that means the condition to determine if a layer is active becomes

[If, (flags==11) || (flags==10) || (flags==15) || (flags==14),

And technically, even this isn’t right, there are four more cases.

The ‘proper’ way to check a layer’s flags to see if it is active is just:

[If, flags & 2, etc.

Hope this is informative.

By the way, Marcus, thanks for the hint on “IClick”.

Ken