I have made the following python script which contains one function, this function creates one simple mesh.

import bpy
import mathutils
from itertools import repeat

def add_single_brick(brick_width, brick_length, brick_height):

    mesh_name = "brick" 
    collection_name = bpy.data.collections.new("BrickCollection")

    vertices_brick = [  (0,0,0),

    edges = []

    faces = [(0,1,2,3),

    new_mesh = bpy.data.meshes.new('brick_mesh')
    new_mesh.from_pydata(vertices_brick, edges, faces)

    # make object from mesh
    new_object = bpy.data.objects.new(mesh_name, new_mesh)

brick_length = 0.21
brick_width = 0.1
brick_height = 0.05    

add_single_brick(brick_width=brick_width, brick_length=brick_length, brick_height=brick_height)

I call the function at the end of the script to create the mesh within a collection I called 'BrickCollection' enter image description here

The mesh is in this collection:

enter image description here

When I run the script again with other variables in the parameters, I want the script to update the existing mesh and not make a new mesh.

I found this post 3: When to use bmesh.update_edit_mesh and when Mesh.update? as in which I understand I should start using the bmesh module

I also found this post

I am getting quite confused, now I have two simple questions:

  • Is there any simple python example of mesh being overwritten within a collection when running the python script again with different parameters?
  • Does the bmesh module also work with modifiers?
  • $\begingroup$ You don't want to create a new object if you want to update the mesh in place. You would have to edit the original object's mesh in place to do that. On the other hand, you could create the new object, then delete the original, and then rename the new object to the old object's name. $\endgroup$ Oct 5, 2021 at 17:59

1 Answer 1


I solved it by making a function which checks if the collection already exists, if it exists it removes the content of the collection before calling the function which makes creates the mesh.

def remove_brick_collection():


    if (bool(bpy.data.collections.get(name_collection))) == True:
        collection = bpy.data.collections.get(name_collection)
        print ("no collection found")

at the end of the script:

add_single_brick(brick_width=1, brick_length=2, brick_height=3)
  • $\begingroup$ You have to remove the mesh as well, not just the collection. Otherwise it keeps creating new meshes and adding them to the file. You can't see them in the GUI but they are there if you look in `bpy.data.meshes'. $\endgroup$
    – N. Virgo
    Oct 15, 2023 at 6:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .