I would like to change the hide_viewport state of a collection in a driver. It is unfortunately not possible to add a driver to a collections's states. (It is possible to do this on objects but not on collections.) The problem is that in the driver editor I can't assign a value to a variable (like var = 0 ) as this results in an "Invalid Python expression". Which is a bit silly as this is just a normal variable value assignment in python.
In an if statement in the driver editor one can assign a value (0 if whatever == something) but this refers to the value of the driven object. As the collection can't have a driver I would like to drive it's states by another object's driver. Is there any way to achieve this?
Basically recreating the bpy.data.collections["Collection_Name"].hide_viewport = True statement from a script in a driver. (I can't use a script as I intend to append the collections and the driver objects in an empty file. Or can I attach a script to an object so that the script also gets appended with the object?)
EDIT: This question is a follow-up to my question from yesterday: Geometry Nodes - Collection Info: turn off visibility of input collection It's about turning off a collection's visibility when it is affected by a "Collection Instance" geometry node, without any user interaction in the object lister.
EDIT 2: To make this question clearer using the example from my other question:
The expression 0 if var == 0 else 1 sets the value of the X Location of the Empty to 0 or 1. But what I would like to have is to set the value of the collection_variable to True or False. Like: (collection_variable = True) if var == 0 else (collection_variable = False) and this is what is unfortunately not possible.
If I understand correctly the variables here are read only and only help to determine the state of the object's attribute which has the driver. Is there any way to set other attributes? (Outside of the scope of the current driver?)