Last active
November 24, 2022 14:00
-
-
Save todashuta/04e0960ef57974cc3ba6801c69cab3d1 to your computer and use it in GitHub Desktop.
selected_objectsそれぞれをactive_objectに設定してなにかするのを便利にする試み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
context = bpy.context | |
def selected_objects_as_active(): | |
for o in context.selected_objects: | |
context.view_layer.objects.active = o | |
yield o | |
for o in selected_objects_as_active(): | |
print(o is context.active_object) # True | |
for o in context.selected_objects: | |
print(o is context.active_object) # Trueは1つだけ | |
# typeで絞り込んだりするときはリスト内包表記の [] ではなく () で囲む (ジェネレーター) | |
for o in (o for o in selected_objects_as_active() if o.type != 'MESH'): | |
print(o) | |
# こういう使い方も可 | |
for _ in selected_objects_as_active(): | |
print(context.active_object) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment