hi all,
im tryng to learn something about how to create my custom panels.
what i’d like to do is to create a main panel with an empty menu and a operator button (like the material one maybe).
the idea is to create a class, pass the class to active object as a property with the button operator (dont know if it is possible if not just a property) and then see the menu showing me that the object has that property/class (maybe with an icon).
the problem is that i cant figure out how to create the list in the panel, i think i have to use My_Class(bpy.types.UIList) to create it but i cant understand how.
any example?
thx
edit: assign a dictionary to active object as a property and panel shows list {“name”:class}
ok i know i was a little bit confused -.-
now i made this:
import bpy
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
EnumProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
PropertyGroup,
)
class Scene_Types(PropertyGroup):
A= StringProperty(name="1")
B =BoolProperty(name="2")
C = IntProperty(name="3")
class My_Name_List(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
pass
#don't know what to do here
elif self.layout_type in {'GRID'}:
pass
class Add_Name_List(bpy.types.Operator):
"""add a name"""
bl_idname = "object.button_add"
bl_label = "Add name"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
sc=context.scene
D = sc.collection.add()
D.name = "D"
print(sc.collection)
return {'FINISHED'}
class My_Panel(Panel):
bl_label = "MyScript Panel"
bl_idname = "OBJECT_PT_myscript"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
sc=context.scene
ob=context.object
layout = self.layout
row=layout.row()
row1=layout.row()
row2=layout.row()
row.label("PANEL")
row1.template_list("My_Name_List", "name", context.scene , "collection", context.scene , "collection_idx",rows=4)
row2.operator("object.button_add" , text = "All")
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.collection = bpy.props.CollectionProperty(type=Scene_Types)
bpy.types.Scene.collection_idx = bpy.props.IntProperty(default=0)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.collection
del bpy.types.Scene.collection_idx
if __name__ == "__main__":
register()
when i run the script it creates a panel but is empty infact if i try to print the collection it results in [0] and if i click the button to add a property to my collection seems to add something but still invisible.
how you can see in the comment in My_Name_List class i don’t know what to do there.
be patient pls and thx for help