Post #2533: : post_02534
๐ท๏ธ Tags
python-scripting intermediate solved
โ๏ธ Related PME Features
- Python Scripting
- Macro Editor
๐ฌ 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