Stop creating new collection if there is one with the same name already in the scene I have a script that creates a new collection but if I run it again it adds a new collection named &quot;Personal Collection.001&quot; and so on, what I would like to tell to the script is that if that collection name is in the scene then don't make a new one.
import bpy

myCol = bpy.data.collections.new('Personal collection')
bpy.context.scene.collection.children.link(myCol) #Creates a new collection


for myCol in bpy.data.collections:
    if myCol.name == &quot;Personal Collection&quot;:
        print (&quot;Collection found in scene&quot;)

Cheers,
Juan
Check it exists and is linked to scene.
IMO Two tests required here, one to test if collection exists, and secondly if it is linked at any level to the current scene.  A quick test for the latter is to see if the scene is a user of the collection.
import bpy
context = bpy.context

# name of collection
name = &quot;Foo&quot;

scene = context.scene

coll = bpy.data.collections.get(name)
# if it doesn't exist create it
if coll is None:
    coll = bpy.data.collections.new(name)
# if it is not linked to scene colleciton treelink it
if not scene.user_of_id(coll):
    context.collection.children.link(coll)

Related
How to get all collections of the current scene?