Making collection active

We can’t set a collection active through the Blender Python API in one step. The “bpy.context.collection” property is read-only, and the “bpy.context.view_layer.active_layer_collection” has a “LayerCollection” type that cannot be set with the standard “Collection” type. To assign an active collection, we need to find the View Layer collection from the desired base collection and already set it as active.

Converting mouse cursor coordinates from area to texture coordinates in Blender Image Editor

In some tools, for example, “eyedropper” or “selection by color”, it is necessary to get the value of the texture pixel that is currently under the mouse cursor. To get pixels data we need to know its coordinates in the texture space.