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