Here are two old Python Tags of mine, that toggles object’s visibility based on different rules. I have find them very useful when you want maximise clarity in your viewport.

Show Only If Active
First tag shows the object only if object is selected (i.e. active). Sometimes this is very helpful, if you have for example bunch of deformers under one object and you want to focus to tweak just one. Just apply this tag to every deformers and then deformer is only visible when it is selected.

import c4d
def main():
    obj = op.GetObject() # Get object
    if obj == doc.GetActiveObject(): # If object is active
        obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 0 # Set 'Visible in Editor' to 'On'
    else: # Otherwise
        obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1 # Set 'Visible in Editor' to 'Off'

show_only_if_active_tag.c4d

Show Only If Correct Camera
Second tag shows the object only if correct camera is active. There are also different options to modify how the tag operates.

def main():
    bd = doc.GetActiveBaseDraw() # Get active base draw
    activeCam = bd.GetSceneCamera(doc) # Get active camera
    targetCam = op[c4d.ID_USERDATA,2] # UD: Assigned camera
    mode = op[c4d.ID_USERDATA,6] # UD: Mode (Default / On)
    invert = op[c4d.ID_USERDATA,4] # UD: Invert
    render = op[c4d.ID_USERDATA,3] # UD: Affect Render Visibility
    obj = op.GetObject() # Get object
    if invert == False: # If invert is not ticked
        if activeCam == targetCam: # If active camera is same as target camera
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = mode # Change editor visibility
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = mode # Change render visibility
        else:
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1 # Editor visibility off
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1 # Render visibility off
    else: # Otherwise
        if activeCam == targetCam: # If active camera is same as target camera
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = mode
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = mode
        else:
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 2
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2

show_only_if_correct_camera_tag.c4d

Cinema 4D, Python, Tag