0
$\begingroup$

I created a custom property group with a list of strings (populated with the name of image textures). How do I compare the list of textures in my scene to this custom property list?

import bpy

class CustomPropertiesGroup(bpy.types.PropertyGroup):
  customString: bpy.props.StringProperty()

bpy.utils.register_class(CustomPropertiesGroup)

bpy.types.Scene.customLists = bpy.props.CollectionProperty(type=CustomPropertiesGroup) 

bpy.context.scene.customLists.clear()

# Filling up the custom list with the texture names 
for m in bpy.data.images:
    if len(m.filepath) != 0:
        newCustomItem = bpy.context.scene.customLists.add()
        newCustomItem.customString = m.name

Later in the code I would like to modify the texture path of those textures which are on my list but I don't know how to iterate over the scene textures and over the custom list at the same time to see if there is a match. This code below doesn't work as it only has the last item in the custom list and therefore it's only true for that last item:

for m in bpy.data.images:
    if m.name in customPropertyGroup.customString:
        print("Something...")

How can I compare the actual m.name to all of the items in the custom list?

$\endgroup$
1
  • 1
    $\begingroup$ if m.name in [pg.customString for pg in bpy.context.scene.customLists]: ? It's called a list comprehension if you want to look it up :) $\endgroup$
    – Gorgious
    Commented Dec 22, 2022 at 20:39

1 Answer 1

0
$\begingroup$

Just to close the question with the super answer from Gorgious:

for m in bpy.data.images:
    if m.name in [pg.customString for pg in bpy.context.scene.customLists]:
        print("Something...")

works perfectly. (Never heard of list comprehension but now I know. Thanks.)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .