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

Closed
opened 2016-04-20 10:48:51 +02:00 by Ondrej Popp · 6 comments

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)
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)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @OndrejPopp

Added subscriber: @OndrejPopp
Author

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"

  • Enum property.
  • Note: the getter/setter callback must use integer identifiers!
    test_items = [
  ("RED", "Red", "", 1),
  ("GREEN", "Red", "", 2),
  ("BLUE", "Red", "", 3),
  ("YELLOW", "Red", "", 4),
  ]
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" - Enum property. - Note: the getter/setter callback must use integer identifiers! test_items = [ ``` ("RED", "Red", "", 1), ("GREEN", "Red", "", 2), ("BLUE", "Red", "", 3), ("YELLOW", "Red", "", 4), ]

This issue was referenced by blender/blender@0b349871d8

This issue was referenced by blender/blender@0b349871d81d61637722d775302a7505b515dd8a

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Bastien Montagne self-assigned this 2016-04-21 12:42:03 +02:00

Added subscriber: @mont29

Added subscriber: @mont29
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-manual#48212
No description provided.