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'

ar_tag_show_only_if_active.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.

import c4d
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
    activeMode = op[c4d.ID_USERDATA,6] # UD: Active mode
    deactiveMode = op[c4d.ID_USERDATA,7] # UD: 
    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 # Set 'Visible in Editor' to mode
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = mode # Set 'Visible in Renderer' to mode
        else:
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1 # Set 'Visible in Editor' to 'Off'
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1 # Set 'Visible in Renderer' to 'Off'
    else: # Otherwise (inverted)
        if activeCam == targetCam: # If active camera is same as target camera
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = mode # Set 'Visible in Editor' to mode
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = mode # Set 'Visible in Renderer' to mode
        else:
            obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 2 # Set 'Visible in Editor' to 'Off'
            if render: # If render is ticked
                obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2 # Set 'Visible in Renderer' to 'Off'

Updated 30/10/2022
> Semantic versioning

ar_tag_show only_if_correct_camera.c4d v1.0.1 (2023.1.2)

Cinema 4D, Python, Tag