2011-02-18 15:27:18 +01:00
|
|
|
"""
|
|
|
|
Collection Example
|
|
|
|
++++++++++++++++++
|
|
|
|
|
|
|
|
Custom properties can be added to any subclass of an :class:`ID`,
|
|
|
|
:class:`Bone` and :class:`PoseBone`.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
|
2011-02-25 17:19:50 +01:00
|
|
|
|
2019-03-21 14:07:06 +01:00
|
|
|
# Assign a collection.
|
2011-02-18 15:27:18 +01:00
|
|
|
class SceneSettingItem(bpy.types.PropertyGroup):
|
2019-03-21 14:07:06 +01:00
|
|
|
name: bpy.props.StringProperty(name="Test Property", default="Unknown")
|
|
|
|
value: bpy.props.IntProperty(name="Test Property", default=22)
|
2011-02-18 15:27:18 +01:00
|
|
|
|
2018-06-26 19:41:37 +02:00
|
|
|
|
2011-02-18 15:27:18 +01:00
|
|
|
bpy.utils.register_class(SceneSettingItem)
|
|
|
|
|
2019-03-21 14:07:06 +01:00
|
|
|
bpy.types.Scene.my_settings = bpy.props.CollectionProperty(type=SceneSettingItem)
|
2011-02-18 15:27:18 +01:00
|
|
|
|
2019-03-21 14:07:06 +01:00
|
|
|
# Assume an armature object selected.
|
2016-04-21 12:16:32 +02:00
|
|
|
print("Adding 2 values!")
|
2011-02-18 15:27:18 +01:00
|
|
|
|
|
|
|
my_item = bpy.context.scene.my_settings.add()
|
|
|
|
my_item.name = "Spam"
|
|
|
|
my_item.value = 1000
|
|
|
|
|
|
|
|
my_item = bpy.context.scene.my_settings.add()
|
|
|
|
my_item.name = "Eggs"
|
|
|
|
my_item.value = 30
|
|
|
|
|
|
|
|
for my_item in bpy.context.scene.my_settings:
|
2011-02-25 17:19:50 +01:00
|
|
|
print(my_item.name, my_item.value)
|