0
$\begingroup$

Please, I would like to know How to make a pointer property for a particle system. My goal is having a prop that contains the particle system name and it updates when the particle system is renamed like what happens to the pointer property for the objects.

As an example, I want to add all the particle systems in the scene into a list then once a particle system removed or renamed the list is updated instantly

Here is an example ( this code belongs to @Karan I've just modified it to fit my example)

import bpy
from bpy.types import Panel

from bpy.props import (
                        StringProperty,
                        IntProperty,
                        CollectionProperty,
                        )


from bpy.types import (
                        Scene,
                        )




class LIST_OT_Action(bpy.types.Operator):
    """ adds an item to the list"""

    bl_idname = 'list.operator'
    bl_label = 'Select an Object Particle System'


    def execute(self, context):

        obj = bpy.context.object
        scene = bpy.context.scene

        # iterate over the scene objs
        for obj in scene.objects:
            
            # checks the p sys
            if(len(obj.particle_systems) != 0):
        
                p_sys_index = 0

                # iterate over the p sys to add it 
                for p_sys in obj.particle_systems:
                    
                    # add list item per p sys 
                    new_item = scene.ID_LIST.add()

                    # set the name ( this is the property i would like to change 
                    # when the particle system renamed that's why I need to link it
                    # with some unique id so I can update absed on that)
                    new_item.name = p_sys.name

        return {'FINISHED'}

class CUSTOM_PT_PANEL(Panel):
    bl_label = "Custom"
    bl_idname = "CUSTOM_PT_PANEL"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Custom"
    
    def draw(self,context):
        layout = self.layout
        obj = context.object
        scene = context.scene
        row = layout.row()
        
        row.label(text= 'Particle System')
        row.template_list( listtype_name="P_UL_LIST",
                            list_id="",
                            dataptr=scene,
                            propname="ID_LIST",
                            active_dataptr=scene,
                            active_propname="ID_LIST_INDEX")
    

class P_UL_LIST(bpy.types.UIList):
    """draws the Reactions list items"""

    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        """draw the items into the list"""

        # split the row for to draw the item icon and name and the status bool
        layout.use_property_split = False             
        split = layout.split(factor=0.95, align=True)

        row_l = split.row(align=True)
        row_l.prop(item, "name", emboss=False, icon = 'PARTICLES')

        
class ListProperties(bpy.types.PropertyGroup):

    # override the default  name property for the list item which carrys the obj name
    name : StringProperty(
    name = '',
    description = '',
    
    )

    # particle sys property    
    ID_LIST_ITEM_OBJ_P_SYS : StringProperty(
    name = 'Particle System',
    description = '',
    default = '',
    
    )



classes = (
    P_UL_LIST,
    ListProperties,
    LIST_OT_Action,
    CUSTOM_PT_PANEL,
)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)

    # register the list propeties
    Scene.ID_LIST = CollectionProperty(type= ListProperties)
    Scene.ID_LIST_INDEX = IntProperty(name= 'index for ID_LIST', default=0)

def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
        
    # unregister the list propeties
    del Scene.ID_LIST
    del Scene.ID_LIST_INDEX
        
if __name__ == "__main__":
    register()

    # call the operator to add p sys
    bpy.ops.list.operator()

Thanks, Mostafa

$\endgroup$
4
  • $\begingroup$ So you want a custom particle system list but it should link to the original particle system list, which means if the original particle system list changes it should reflect in your custom list. $\endgroup$
    – Karan
    Commented Apr 26, 2023 at 14:16
  • $\begingroup$ @Karan Yes, That's exactly what I'm looking for. That's why I'm searching for a way to have the particle system maybe as a pointer to be able to have a link between them. $\endgroup$ Commented Apr 26, 2023 at 15:15
  • $\begingroup$ But if both the list should be same then why you need custom list instead use default particle system list $\endgroup$
    – Karan
    Commented Apr 26, 2023 at 16:02
  • $\begingroup$ @Karan because I'm planning to add particle systems from more than one object. Also, I need to have my own and design for the list. I'm just wondering how blender doesn't have a pointer to store the particle systems? $\endgroup$ Commented Apr 26, 2023 at 16:31

1 Answer 1

0
$\begingroup$
import bpy
from bpy.types import Panel


class CUSTOM_PT_PANEL(Panel):
    bl_label = "Custom"
    bl_idname = "CUSTOM_PT_PANEL"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Custom"
    
    def draw(self,context):
        layout = self.layout

        if context.object:
            row = layout.row()
            row.template_list("PARTICLE_UL_particle_systems", "", context.object, "particle_systems", context.object.particle_systems, "active_index", rows=3)
        
    
classes = (
    CUSTOM_PT_PANEL,
)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)

    
def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
        
        
if __name__ == "__main__":
    register()
$\endgroup$
3
  • $\begingroup$ Thanks Karan for the code example. Is there a way to get a unchanged id for the particle systems in blender. I've tried pointers but they are change when the object is deleted $\endgroup$ Commented Apr 25, 2023 at 14:04
  • $\begingroup$ Please, phrase your question properly with code example. $\endgroup$
    – Karan
    Commented Apr 25, 2023 at 14:16
  • $\begingroup$ Sure @Karan I've just uploaded a code example using your example as base. $\endgroup$ Commented Apr 25, 2023 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .