I made a small script that is supposed to select objects that have a material with an Image Texture.
import bpy
scene = bpy.context.scene
bpy.context.view_layer.objects
#first make sure everything is unselected
for obj in bpy.data.objects:
obj.select_set(False)
for ob in bpy.data.objects:
if ob.type == "MESH": #select only meshes
for mat_slot in ob.material_slots:
# if mat_slot.material:
if mat_slot.material.node_tree:
# print("material:" + str(mat_slot.material.name))
for x in mat_slot.material.node_tree.nodes:
if x.type=='TEX_IMAGE':
ob.select_set(True) #select if object has texture
When running the script for a particular scene it gives me the following error:
RuntimeError: Error: Object 'pape01t.002' can't be selected because it is not in View Layer 'ViewLayer'!
After some digging I found the objects in current file collection
There is no option to turn them on (visible) so
- How come these objects are in the current file collection but not visible in the actual object list [view layer] or [scene collection]?
- How would I be able to ignore such objects or even better, find these hidden objects and delete them by script?