Really basic Python

Hello,

I’m starting to digging into Python and Blender, and I’m having some troubles to do what I want, even though when digging into the API doc and on StackExchange.

In this case I’m trying to select the result of a Separate operation for further processing.

detachedPolys = bpy.ops.mesh.separate(type='SELECTED')
detachedPolys.name = ("poly_temp")
bpy.ops.object.mode_set(mode='OBJECT')
bpy.context.scene.objects.active = detachedPolys

I guess the 2nd line is totally wrong, so I looked for a way to select the Selected object (so the result of the Separate operation ) and make it active but failed.

subD_CC

Ok I hacked a bit my code. Inverting the selection before the Separate operation makes the target object active in Object mode, all good.

Now I’m looking for a way to store the selected vertices and reselect it after the operation.

def subdivideCC():
    bpy.ops.mesh.select_all(action='INVERT')
    bpy.ops.mesh.separate(type='SELECTED')
    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.ops.object.modifier_add(type='SUBSURF')
    bpy.context.object.modifiers["Subsurf"].levels = 1
    bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
    bpy.ops.object.join()
    bpy.ops.object.mode_set(mode='EDIT')

subdivideCC()