Hi @dskeith thanks for reaching out us.
As pointed out by @PluginStudent, the NBIT_SOLO_LAYER behavior is explained in the Layer Manuel although it make sense to add a note to the Python API as well.
With regard to a complete example, I've partially reworked your code to make sure that by executing the script multiple times you can run across all the solo configurations that the scene can handle.
import c4d
# Main function
def main():
layer_root = doc.GetLayerObjectRoot()
if not layer_root:
return
# Get the first layer in the scene
layer = layer_root.GetDown()
if not layer:
return
soloSet = False
while layer is not None:
# Set `rawdata` to True flag so to get the original layer values without any additional global changes
layer_data = layer.GetLayerData(doc, rawdata=True)
# check the current layer solo state:
if layer_data["solo"] == False:
# if not "solo" then set to True
layer_data["solo"] = True
# update the layer
layer.SetLayerData(doc, layer_data)
# update the flag
soloSet = True
break
# deactivate if layer solo was True
layer_data["solo"] = False
layer.SetLayerData(doc, layer_data)
# go to next layer
layer = layer.GetNext()
# if one (or more) solo was set the set NBIT_SOLO_LAYER otherwise clear
if soloSet == True:
doc.ChangeNBit(c4d.NBIT_SOLO_LAYER, c4d.NBITCONTROL_SET)
else:
doc.ChangeNBit(c4d.NBIT_SOLO_LAYER, c4d.NBITCONTROL_CLEAR)
# Add an event
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()
Cheers