Convert all particle objects in an object via script

Hi there,
I am new at scripting for Blender, and I have been successful writing a couple of scripts now. I have a new problem though, I am trying convert all instances made by a particle system and then join them with the parent. How can I achieve this through code?

Thank you,
mStuff

Select the object which has a particle system modifier then run this script…


import bpy


bpy.ops.object.duplicates_make_real()
#deselect active object
bpy.context.scene.objects.active.select = False
bpy.ops.object.parent_to_empty()

nice, the duplicates_make_real was the operator I was looking for - the rest of the script is error-ing for me though

but I think it is fine, the operator should be enough to make my life a whole lot easier

Thanks!

Works with Blender v2.77, maybe errors with v2.78.