0

I want to be able to change the names of items directly in the list (using double-clicking). But at the moment, the list cannot be edited. Maybe I forgot to put the right attribute somewhere, or am I using the wrong logic? Tell me please.

Script

import bpy, sys, os
from bpy.props import EnumProperty, StringProperty, IntProperty, CollectionProperty, PointerProperty, BoolProperty
from bpy.types import PropertyGroup, UIList, Operator, Panel
from dataclasses import dataclass

data_for_enum_presets = [] presets_list=[] dir_path = 'E:\' pres_name = "scout" last_action = ''

class BONES_PG_ListBones(PropertyGroup): bone: StringProperty( name="Name", description="A name bone", default="Bone")

class BONES_ListBones(UIList): def draw_item(self, context, layout, data, item, icon, acive_data, active_propname, index): custom_icon = 'BONE_DATA' bone = item.name

    if self.layout_type in {'DEFAULT', 'COMPACT'}:
        layout.label(text=item.name, icon=custom_icon)
        #layout.prop(bone, "name", text="", emboss=False)
    elif self.layout_type in {'GRID'}:
        layout.alignment = 'CENTER'
        layout.label(text="", icon=custom_icon)
def invoke(self, context, event):
    print(bpy.context.scene.list_bones_id)
    pass

class BONES_ReloadPresets(Operator): bl_label = "Reload preset" bl_idname = "bones.reload_preset" bl_description = "Update information in presets."

def execute(self, context):
    bones_reload_presets(self, context)
    return {'FINISHED'}

def enum_presets_list(self, context): enum_presets = [] count = 0 for obj in data_for_enum_presets: identifier = str(obj) name = str(obj) description = str(obj) number = count enum_presets.append((identifier, name, description, number)) count += 1 return enum_presets

def update_enum_presets_list(self, context): enum_list_presets_clearAllBones(self, context) if bpy.context.scene.list_presets.presets == 'Scout': enum_list_presets_showBone(self, context, 0) elif bpy.context.scene.list_presets.presets == 'Heavy': enum_list_presets_showBone(self, context, 1) elif bpy.context.scene.list_presets.presets == 'Heavy_duty': enum_list_presets_showBone(self, context, 2) elif bpy.context.scene.list_presets.presets == 'Highway': enum_list_presets_showBone(self, context, 3) elif bpy.context.scene.list_presets.presets == 'Offroad': enum_list_presets_showBone(self, context, 4) return None

def bones_reload_presets(self, context): preset=[] preset.clear() presets_list.clear() data_for_enum_presets.clear()

bones_load_presets()

update_enum_presets_list(self, context)
return{'FINISHED'} 

class ListPresets(PropertyGroup): presets: EnumProperty( name= "Preset", description= "", items= enum_presets_list, update= update_enum_presets_list )

def bones_load_presets(): preset=[] tmp=[] counter=0

f=open(dir_path+'scout.txt','r')
data_for_enum_presets.append('Scout')
preset=f.readlines()
preset=preset[::2]
f.close()
presets_list.append(preset)

return{'FINISHED'}   

def enum_list_presets_showBone(self, context, preset_num): for i in range(len(presets_list[preset_num])): context.scene.list_bones.add() context.scene.list_bones[i] context.scene.list_bones[i].name = presets_list[preset_num][i] context.scene.list_bones[i].name = context.scene.list_bones[i].name.replace('\n','') return None

def enum_list_presets_clearAllBones(self, context): list_bones = context.scene.list_bones index = context.scene.list_bones_id

for i in range(len(list_bones)):
    index = context.scene.list_bones_id
    list_bones.clear()
    context.scene.list_bones_id = 0

return{'FINISHED'}

class BONES_PT_ListBones(Panel): bl_label='Bones' bl_space_type='VIEW_3D' bl_region_type='UI' bl_category='Bones'

def draw(self, context):
    layout = self.layout
    scene = context.scene
    props = context.scene.ui_props

    rows = 2
    row = layout.row()
    row.template_list('BONES_ListBones', 'The List', scene, 'list_bones', scene, 'list_bones_id')
    row = layout.row()
    row.operator('bones.reload_preset', icon="PRESET")

classes = [ BONES_PG_ListBones, ListPresets, BONES_ListBones, BONES_ReloadPresets, BONES_PT_ListBones ]

def register(): for cls in classes: bpy.utils.register_class(cls) bpy.types.Scene.list_bones = CollectionProperty(type = BONES_PG_ListBones) bpy.types.Scene.list_bones_pp = PointerProperty(type = BONES_PG_ListBones) bpy.types.Scene.list_presets = CollectionProperty(type = ListPresets) bpy.types.Scene.list_presets = PointerProperty(type = ListPresets) bpy.types.Scene.list_bones_id = IntProperty(name = "Index for list_bones", default = 0) bpy.types.Scene.active_object_index = IntProperty()

def unregister(): del bpy.types.Scene.list_bones del bpy.types.Scene.list_bones_id del bpy.types.Scene.list_presets del bpy.types.Scene.ui_props

for cls in classes:
    bpy.utils.unregister_class(cls)

if name == "main": bones_load_presets() register()

Scout.txt

BoneChassis_cdt
-0.967 -0.0 0.988
BoneAxle2
-1.166 -0.0 0.56
BoneExhaust
-1.761 0.315 0.725
BoneAxle1
1.411 0.0 0.56

0 Answers0