Get the ViewLayer of a Mesh If you wished to cull meshes/lights/cameras for export, based on the value of exclude value of the view layer of the collection that the object was in, how would you find the view layer?

While the names of the collection &amp; view layer are the same, this much more complicated due view layers being able to be inside of view layers.

The tree of view layers starts at
bpy.context.window.view_layer.layer_collection for the master collection, the top level view layers are in .children, but each of those can also have .children.

Kind of seems like I would just need to resort to checking .visible_get() on the object.  Was already using that to indicate in the export whether the object should be visible on import though.
I do not know that a mesh can have more than one item for users_collection.  Assuming not then this works.

def shouldBeCulled(self, object):
    collectionName = object.users_collection[0].name
    return self.collectionExcluded(bpy.context.window.view_layer.layer_collection, collectionName)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def collectionExcluded(self, viewLayer, collectionName):
    print('looking for ' + collectionName + ' in ' + viewLayer.name)
    if collectionName == viewLayer.name: 
        return viewLayer.exclude

    for childViewLayers in viewLayer.children:
        result = self.collectionExcluded(childViewLayers, collectionName)
        if result is not None:
            print('result for ' + collectionName + ' is ' + str(result))
            return result

    return None