Delete objects based on name prefix

Kind of noobish question:
I’m working on an add-on in 2.8 and I managed to get to a point that is working fine except I don’t know how to delete permanently the items that are added.
So my example is the following:
I’m generating a cube through a panel add-on I’m able to define a prefix and add the standard name to it:

001- Cube

001 is the prefix with the cube it also generates a
001-Cube.txt as an internal file.
How can I delete everything that is associated with the 001-Cube name geometry text file etc, through python?

Thank you for help.

bpy.ops.object.delete() will delete an object and all associated single-user data. If you’d rather not use an operator, you can use the data api and remove it with, but you’ll also have to manually remove any of the associated data (which is done in the same way).

as for any custom files you created, you just use normal file io to delete those: os.remove("001-Cube.txt")

1 Like

Thank you. So basically I can create a drop-down menu or a picker and using the two lines I can generate the deletion for text object and data?

should be possible, yes

1 Like

This is not working :slight_smile:

Text file location is internal inside blend file it will never be saved to the disk.

oh well in that case it’s just in the data api- remove it the same way you remove objects/meshes/whatever.['001-Cube.txt']

1 Like