JuhaW
(JuhaW)
October 25, 2014, 2:22pm
1
So declaring one FloatProperty and it can be use with index ?
bpy.types.Scene.Power = FloatProperty(
name = "Light power %",
description = "Enter a float",
default = 1,
min = -100,
max = 1000,
precision = 2)
scn = bpy.context.scene
#I dont know the syntax but like this way
for i in range(7)
scn[i,'Power'] = 5.0
It would be much easier to use it in UI panels also with index
CoDEmanX
(CoDEmanX)
October 26, 2014, 4:00am
2
you can use a FloatVectorProperty() for a static array of floats for up to 32 elements:
>>> bpy.types.Scene.power = bpy.props.FloatVectorProperty(size=7)
>>> bpy.context.scene.power[0] = 1.5
>>> bpy.context.scene.power[6] = 4.44
>>> bpy.context.scene.power[:]
(1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 4.440000057220459)
If you need more than 32 or dynamic size, use a CollectionProperty() with a FloatProperty() in its PropertyGroup class:
import bpy
class PowerArray(bpy.types.PropertyGroup):
value = bpy.props.FloatProperty()
bpy.utils.register_class(PowerArray)
bpy.types.Scene.power = bpy.props.CollectionProperty(type=PowerArray)
p = bpy.context.scene.power
p.clear() # clear from previous run
item = p.add()
item.value = 1.5
item = p.add()
item.value = 4.44
for i, item in enumerate(p):
print("power[%i].value = %f" % (i, item.value))
print("swap 1st and 2nd item")
p.move(0, 1)
for i, item in enumerate(p):
print("power[%i].value = %f" % (i, item.value))
Output:
power[0].value = 1.500000
power[1].value = 4.440000
swap 1st and 2nd item
power[0].value = 4.440000
power[1].value = 1.500000
JuhaW
(JuhaW)
October 26, 2014, 1:36pm
3
Oh yes, I tested CollectionProperty and its very welcome to my Arsenal.
Thank you Codeman so much.