access a separated object with python


I’m separating objects in python. How can I properly access the object, that has been just separated? I could go for something like name convention (Plane -> Plane.001, Plane.002), but this would be so ugly. There must be another way! WHY DOESN’T the separate operator return the object it separated? That would be so much easier.

Here’s the code I had, just before I realised, that I am adding the wrong object to my list…

# here I select my faces/edges/vertices 
# (why do I need to do this in object mode?!? my code is full of toggles...)
#here I would like to append the newly created object I just separated...

Here’s the file: dreieck_2.blend (354 KB)

you can make a list of mesh before separate the mesh and another list after.
Then you remove all what is in the first list from the sconde and your have your new mesh

WHY DOESN’T the separate operator return the object it separated?
Because you are using bpy.ops. Eventually you will realize you can write your own functions that manipulate directly. You are taking a shortcut to coding a solution by using bpy.ops. When you write your own functions you can offer a return value such as the object just separated.

But what kgeogeo says is valid and would probably work.
For instance…

import bpy
l_before = len(
# Now issue your bpy.ops command.
l_after = len(
print(l_before, l_after)

How would I do this? And why when the “separate” command is already there?

Thank you for the hint on len( I guess that’s my workaround for now.

lo_b = [ob for ob in if ob.type == ‘MESH’]
lo_a = [ob for ob in if ob.type == ‘MESH’]

for i in lo_b:
separate_object = lo_a[0]

For Atom: yes It’s possible to write your own function but it’ll be slower because Python is slower als C I think.

Just an FYI. I have found many bpy.ops operations to be much slower than operating directly upon I never really worry about speed, I just focus on functionality. Make it work first, then optimize (if needed). Most python scripts are just a way to get to the next project and they have a shelf life of about 3 months before the API changes and they fall out of scope. If you are writing game code for the game engine then speed is more of a concern.

And why when the “separate” command is already there?
It is there to offer the feature for the interface. Which is user driven. Thus the context is provided by the user at run time.

Here is a way to navigate mesh data.

import bpy
ob ="Cube")
if ob != None:
    me =
    for face in me.polygons:
        if == True:

When I am writing scripts I often use the Help menu of Blender to bring up the search website for the API.

To separate a face from an object. You are really creating two objects from a single source. One object contains all the faces except the selection set and the other is the inverse. Then you remove the source object from the scene.