I created a Python like this
bpy.ops.object.move_to_collection(collection_index=2, new_collection_name="Background")
But this code must have a collection called "Background" in the scene from the beginning
I want this.
- If there was no collection called "Background", we would create one with Python and move the selected object
- If the "Background" collection exists, just move it instead of creating a new one
And I'd like to go from ViewPort to Hide I created this code, but I don't know how to specify the "Background"
bpy.context.scene.hide_viewport = True
Digression
With just these two lines, I was able to create Empty if it wasn't there and select it if it was there.
bpy.ops.object.select_pattern(pattern="Empty")
bpy.ops.object.constraint_add_with_targets(type='TRACK_TO')
=====Edit=====
I was putting up the wrong code.
bpy.context.scene.exclude = True
When I modified it in this way, I get an error
bg_col.hide_exclude = True
bpy
structure. Then this question need to split in several question to make it more general (or module? Atomic question?) to help other reuse this Q&A. $\endgroup$ – HikariTW Jul 29 '20 at 8:43