I am a bit lost in understanging how store classes and / or property groups ,
I have followed 2 tutorials that add property groups in the Scene
(and i can see them from the panel property - custom property)
And another one have placed the properties in a scene collection
(But i dont understand if there is a panel to see these properties)
so i was wondering if i can store more complex structure of variables inside objects.
and how to do it.
PS: can you explain me the difference between the concept and usage of propertygroup and class?
add a single property to an objects in the scene : bpy.data.objects["Cube"][" Password "]=51
Add single property to master scene collection : bpy.context.scene.collection[" Password "] =51
Add single property to a specific collection : bpy.data.collections["MYCOLL"]["VARIABLE"]=51
Can i store / add a class to an object ?
class BOX():
LABEL="KITCHEN"
N=14
Can i store / add propertygroup to an object ?
class MyPropertyGroup(bpy.types.PropertyGroup):
custom_1: bpy.props.FloatProperty(name="My Float")
custom_2: bpy.props.IntProperty(name="My Int")
addressing your questions in the order you asked them:
Can you explain me the difference between the concept and usage of propertygroup and class
A class is a python concept, a propertygroup is Blender specific. a class is a necessary ‘object’ concept (object as in- object oriented programming, not a “blender object”). A property group is used for storing custom properties on blender objects. They are not interchangable, and are entirely different concepts that are not compatible with each other.
Can i store / add a class to an object
No. A property group is the only “api” way to store custom structured data on a blender object. you cannot assign a class object to a custom property. If you try, python will throw an exception that explains why.
Can i store / add propertygroup to an object ?
Yes. after your propertygroup is registered, you can assign it like any other custom property.
def register():
bpy.utils.register_class(MyPropertyGroup)
bpy.types.Object.test_prop= MyPropertyGroup
# and then later, elsewhere in code
context.active_object.test_prop.custom_1 = 51.0
context.active_object.test_prop.custom_2 = 14
Side note: use the code tags when posting code, makes reading your post a lot easier if you do.
Aaaaaaaa thank you very much man !
i understand the mess i made now ,
I have made this test here,
and it successfully add the propertygroup to the object ,
but its like all the object share the same?
if i set the variable inside the cube01 and cube02 , when printed they are the same, the last i setted.
?
Taking a look at the code for the MeasureIt add-on might be helpful here. MeasureIt is included with recent versions of Blender. It can assign custom data to objects and display that data in a panel.