I hope to generate ID properties only for context.object, with python and make UI slider to controll them as add on. Then I hope to know way, to make slider for dictionary type ID property items value.
I can generate dictionary type ID property, then set float for items, and can use items for driver too.
class WTF_OP_Operator(bpy.types.Operator):
bl_idname = "object.propgroup"
bl_label = "Add group custom props"
@classmethod
def poll(cls, context):
return (context.active_object)
def execute(self, context): #add ID props (dictionary type and float)
mob = context.active_object
mob["mygroup"] ={}
mob["test"] = 0.333
mgroup = mob["mygroup"]
print("mgroup type:", type(mgroup))
mgroup["prop1"] = 1.0
mgroup["prop2"] = 0.5
print("mgroup items:", mgroup.items())
return {'FINISHED'}
If ID properties type were “Float, Integer”, I can make slider for the ID property with use Panell class and prop, like that,( not set min, max etc though we can)
def draw(self, context):
mob = context.active_object
layout = self.layout
row = layout.row()
row.operator("object.propgroup") #generate IDprops for mob
if not mob.get("test") == None
box = layout.box()
row = box.row()
row.label(text = "test:")
row.prop(mob, '["test"]', slider=True)
if not mob.get("mygroup") == None :
box = layout.box()
row = box.row()
row.label(text = "mygroup")
row = box.row()
row.label(text = "prop1:")
row.prop(mob, '["mygroup"]["prop1"]', slider=True) # not work why?
About mob[“test”] it work as expected. ([“test”] is float type id property.
But About mob[“mygroup”][“prop1”] (dicitonary type ID property, “prop1” items value)
When I set path [“mygroup”][“prop1”] for layout.prop, I get log from console.
rna_uiItemR: property not found: Object.[“mygroup”][“prop1”]
But if I set the data path [“mygroup”][“prop1”] for driver, it work without problem.
and I can still set values, or get values, of mob[“mygroup”][“prop1”]
so why it not work to generate prop(slider) for layout? Is there way to correct it to work? then I tried to use bpy.types.PropertyGroup too, but I could not get it work.,
and I only hope to add property for my selected object.
And here is my test add on full code(for 2.8) when click button it add ID properties for current selected object. then generate panell. (but the dicitonary type ID properties, not work for the items,)
import bpy bl_info = { "name": "property group test", "author": "Engetudo", "version": (1, 0), "blender": (2, 80, 0), "location": "View3D > Sidebar", "description": "property test", "warning": "test only", "support": "TESTING", "category": "User Interface" } """ class WTF_PG_testGroup(bpy.types.PropertyGroup): prop1: bpy.props.FloatProperty(name="prop1") prop2: bpy.props.FloatProperty(name="prop2")""" class WTF_OP_Operator(bpy.types.Operator): bl_idname = "object.propgroup" bl_label = "Add group custom props" @classmethod def poll(cls, context): return (context.active_object) def execute(self, context): #add ID props (dictionary to group) mob = context.active_object mob["mygroup"] ={} mob["test"] = 0.333 mgroup = mob["mygroup"] print("mgroup type:", type(mgroup)) mgroup["prop1"] = 1.0 mgroup["prop2"] = 0.5 print("mgroup items:", mgroup.items()) return {'FINISHED'} class WTF_PT_propgroups(bpy.types.Panel): bl_idname = "object.props_panell" bl_label = "WIF Prop Group test" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Prop-test" @classmethod def poll(cls, context): return (context.active_object) def draw(self, context): mob = context.active_object layout = self.layout row = layout.row() row.operator("object.propgroup") if not mob.get("test") == None : box = layout.box() row = box.row() row.label(text = "test:") row.prop(mob, '["test"]', slider=True) if not mob.get("mygroup") == None : mgroup = mob["mygroup"] box = layout.box() row = box.row() row.label(text = "mygroup") row = box.row() row.label(text = "prop1:") row.prop(mob, '["mygroup"]["prop1"]', slider=True) classes = [ WTF_OP_Operator, WTF_PT_propgroups, ] register, unregister = bpy.utils.register_classes_factory(classes)
Apreciate any help and advices.