0
$\begingroup$

I'm trying to search for all items in bpy.context.scene that have same name, but different suffix number (bpy.context.scene["list_1"], .["list_2"] etc.
It works if I search for objects under bpy.context.scene.objects:

for ob in bpy.context.scene.objects:
    if "list" in ob.name:
        print("woohoo!")

But as for items that are stored under scene, I get this error: "TypeError: 'Scene' object is not iterable"

How can I search through these items and remove them from scene with a script? Some have used len() and range() with good result, but I haven't managed to make it work?

Any ideas? :)

$\endgroup$
0
$\begingroup$

You are searching for ID properties of the scene objects ie scene[idprop]

The list of all custom properties names of the scene will be in scene.keys()

The keys() method of a blender object returns a list of all custom property names.

for key in scene.keys():
    if key.startswith("list"):
        print("scene['%s'] = " % key, scene[key].to_list())

Similarly the items() method returns a list of key value pairs

for key, val in scene.items():
    if key.startswith("list"):
        print("scene['%s'] = " % key, val.to_list())

also lets say we want "list_2" but don't know if it exists, if it doesn't scne["list_2"] will throw a key error, in this case recommend using get

list2 = scene.get("list_2")
if list2 is not None:
    print(list2.to_list())
else:
    print("no list named list_2 in scene")

or list2_exists = "list_2" in scene.keys() could be used.

$\endgroup$
  • $\begingroup$ for ob in scene.keys(): if ob.startswith("selSet"): bpy.ops.wm.properties_remove(data_path="scene", property=ob) $\endgroup$ – Bjarki Guðmundsson May 18 '18 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.