📋 Metadata
- Author: roaoao
- Date: 2019-07-22 16:36:43
- Type:
answer - Reply to: post_02531
- Replies (1): post_02534
💬 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