Page MenuHome

Example of Collection property definition suggests by the print statement that three values are added while in fact only two are.
Closed, ResolvedPublic

Description

Hello there,
I have just started to learn python/blender,

Now, in the following text on a property collection definition, the print statement suggests that three values are added while in fact only two are. Unless I am mistaken, but I don't think so.

kind regards,
Ondrej Popp

https://www.blender.org/api/blender_python_api_2_77_0/bpy.props.html?highlight=property

import bpy

Assign a collection

class SceneSettingItem(bpy.types.PropertyGroup):

name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
value = bpy.props.IntProperty(name="Test Prop", default=22)

bpy.utils.register_class(SceneSettingItem)

bpy.types.Scene.my_settings = \

bpy.props.CollectionProperty(type=SceneSettingItem)

Assume an armature object selected

print("Adding 3 values!")

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:

print(my_item.name, my_item.value)

Event Timeline

Ondrej Popp (OndrejPopp) raised the priority of this task from to 90.
Ondrej Popp (OndrejPopp) updated the task description. (Show Details)
Ondrej Popp (OndrejPopp) edited a custom field.

In addition, the second tupple element in the enum example is all "red", and although this is not important to understand the example, I think maybe the second tupple elements should follow their first one, meaning "Red"/"Green"/Blue"/"Yellow"

  1. Enum property.
  2. Note: the getter/setter callback must use integer identifiers!

test_items = [

("RED", "Red", "", 1),
("GREEN", "Red", "", 2),
("BLUE", "Red", "", 3),
("YELLOW", "Red", "", 4),
]