Linking render visibility to viewport visibility in 2.81? While there may be cases when you want to render objects other than the ones you see in the editor, you more often need to prevent such difference and have in the render exactly the objects visible in the editor.

Is it possible to lock (meaning keep them in sync) visibility in render to visibility in viewport, so that you get what you see and don't need to search objects one by one to ensure you'll render all and only the objects currently in the editor?

Said otherwise how to keep in sync any pair of icons, at object level, at collection level, and whatever other levels if I forgot some. In sync meaning when one changes the other changes too, as if there was only one icon. In more conventional GUI, this lock is usually represented by a chain link icon:

  

Question for Blender 2.8.



By the way I don't understand why the active camera view doesn't show objects with render = visible, and rather show objects with viewport = visible. Camera views are supposed to be the ones which are rendered. So there is no way to preview what will be rendered.
I found half of the answer to this problem here:
Why are there non-visible objects in my final render?

You may paste the following code line to the Python Console (at the
bottom of the Scripting view) and hit return, to make the render
visibility match the viewport visibility automatically:
for ob in bpy.context.scene.objects: ob.hide_render = ob.hide

As someone pointed out, in blender 2.8+ you need to adapt the code to:
for ob in bpy.context.scene.objects: ob.hide_render = ob.hide_get()

This will only do it once though and not permanently link the two. If someone knows how to adapt this to link them continuously, that would be great!
EDIT:
I wrote a short add-on that syncs the render ports with the current view ports through the click of a button in the collections panel. You need to click every time you want to synchronise.

Installation
If you are interested, you can download the add-on here:
https://github.com/Nayunis/Blender/blob/master/sync_render_with_view.zip
Just copy the unpacked folder into the blender add-ons folder (something like C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\addons)
Then you can activate the add-on within blender via:
Edit &gt; Preferences &gt; Add-Ons (in the left menu) and search for &quot;Sync Render with Viewport&quot; and tick the little box to activate it. Now the button should be there.