Disable an object from the viewlayer


How can I disable an object from the current view layer (the computer screen icon) ?

C.object.hide_viewport=True only hides it in the viewport. I would like to disable the objects in the viewlayer because it seems like they are still processed if they are enabled in the View Layer but hidden from it.

The ui action produces almost the same Python output , so that is not very useful.


I found a solution after digging further. Here is how to do it in case someone else needs it too.