📋 Metadata

💬 Content

RaphaelBarros:

I’m having some trouble converting some code to a single line.
How can I convert “fors” and “ifs” to this single line codes?

In some cases it’s impossible. But in your case you can use list comprehensions:

for ob in scene.objects:
    if ob.type == 'MESH':
        scene.objects.active = ob;
        break;



mehses = [ob for ob in scene.objects if ob.type == 'MESH']; scene.objects.active = meshes[0] if meshes else scene.objects.active



for ob in scene.objects:
    if ob.type == 'EMPTY':
        scene.objects.unlink(ob)
        bpy.data.objects.remove(ob) 



[(scene.objects.unlink(ob), bpy.data.objects.remove(ob)) for ob in scene.objects if ob.type == 'EMPTY']

❤️ 1 likes


🔗 View on Blender Artists