Advanced particle joining with bpy

I wonder if anyone knows of a way to join particles created with the BI renderer (after having been made real) according to the face they spawned out of. In this simplified example, I am trying to join the objects according to the faces they spawned from using the seams as boundaries to determine which faces belong together. I understand this may not be explicitly a BGE question, but I thought there might be someone here who has done something similar. I would appreciate any thoughts, advice, or redirects to information that could help me.


Taking it 1 step further, I would then separate the plane into 2 objects using the seams as boundaries, and then join the joined particles to the plane’s from which they spawned. I use these scripts to create vertex groups from seams, and create individual objects from vertex groups.


#Create vertex groups from seams
import bpy
import bmesh


bpy.context.tool_settings.mesh_select_mode = (False, False, True)


for ob in bpy.context.selected_objects:
    if ob.type == 'MESH' and bpy.ops.object.mode_set.poll():
        
        bpy.context.scene.objects.active = ob
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        
        me = ob.data
        bm = bmesh.from_edit_mesh(me)
        
        faces = bm.faces[:]
        
        while faces:
            bpy.ops.mesh.select_all(action='DESELECT')
            face = faces.pop()
            face.select_set(True)
            
            bpy.ops.mesh.select_linked(delimit={'SEAM'})
            bpy.ops.object.vertex_group_assign_new()
            
            for f in bm.faces:
                if f.select:
                    try:
                        faces.remove(f)
                    except:
                        pass


        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

#written by JA12
#create objects from vertex groups
import bpy


for obj in bpy.context.selected_objects:
    if(obj.type == 'MESH' and len(obj.vertex_groups) > 0):
        bpy.context.scene.objects.active = obj
        bpy.ops.object.mode_set(mode='EDIT')
        bpy.ops.mesh.select_mode(type='VERT')
        for vgroup in obj.vertex_groups:
            bpy.ops.mesh.select_all(action='DESELECT')
            bpy.ops.object.vertex_group_set_active(group=vgroup.name)
            bpy.ops.object.vertex_group_select()
            bpy.ops.mesh.separate(type='SELECTED')
        bpy.ops.object.mode_set(mode='OBJECT')

Feel free to tweak or combine these scripts as needed to achieve the end result.

In further researching, I found I could create a custom object property that might be able to serve as a “flag”. Can anyone recommend a tutorial on custom properties I can read up on? I am sure this is going to end up requiring some python wizardry and I will probably end up posting this as a job, assuming I can confirm its viability.