Define blender Propertys in a Cycle
<p>I am trying to define a number blender property that is the same as the face of a cube, without defyning them manually.</p>

<p>So something like this:</p>

<pre><code>atr = bpy.types.Scene
for i in range(0,20):
    //Define a intProperty to do stuffs.
</code></pre>

<p>And the call them separately in the panel draw function, is it possible?</p>

<p>There are two ways to add new properties to objects in blender. A simple dynamic way is to use <a href="https://www.blender.org/api/blender_python_api_current/info_quickstart.html#custom-properties" rel="nofollow">custom properties</a> by assigning a value to a key as if the object was a dictionary. This is the same as using the custom properties panel in the <a href="https://www.blender.org/manual/editors/properties/introduction.html" rel="nofollow">object properties</a>. To access this value in your script you keep using the dictionary style - <code>obj['myprop0']</code></p>

<pre><code>import bpy
obj = bpy.context.object
for i in range(0,20):
    obj['myprop'+str(i)] = i
</code></pre>

<p>A more structured way that allows type checking so that you can for example only assign an int to the property, is to add the <a href="https://www.blender.org/api/blender_python_api_current/bpy.props.html" rel="nofollow">property to the object class definition</a>, these also show in the custom properties panel but show as "API Defined". To do this with generated property names means you want to execute a piece of code that you generate. This method creates a true property that you access the same as other properties in the class definition - <code>obj.myprop0</code></p>

<pre><code>import bpy
for i in range(0,20):
    cmd = 'bpy.types.Object.myprop{} = bpy.props.IntProperty()'.format(i)
    exec(compile(cmd, 'myprops', 'exec'))
</code></pre>

<p>Be aware that both approaches occupy the same namespace, so if you use the same property name in both methods you will be accessing the same property and both methods of displaying the property will work. The <code>bpy.props</code> definitions override the dictionary style properties.</p>

<p>Each approach is accessed a little differently when displaying the property in a panel. For the dictionary style property you use <code>row.prop(obj,'["myprop'+str(i)+'"]')</code> while when using <code>bpy.props</code> you use <code>row.prop(obj,'myprop'+str(i))</code> - note that the first approach you use a property name that is contained in <code>[]</code> like accessing any dictionary value.</p>

<pre><code>import bpy
class myPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "My properties Panel"
    bl_idname = "OBJECT_PT_myprops"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        obj = context.object

        row = layout.row()
        row.label('dynamic properties')
        for i in range(0,20):
            row = layout.row()
            row.prop(obj,'["myprop'+str(i)+'"]')

        row = layout.row()
        row.label('structured properties')
        for i in range(0,20):
            row = layout.row()
            row.prop(obj,'myprop'+str(i))

bpy.utils.register_class(myPanel)
</code></pre>

python properties blender