How to create scene properties from a string name

Hello (awesome) Blender gurus!

I have a piece of code that stores properties into a scene as such:
bpy.types.Scene.MyPropertyName = FloatProperty(name=“Test Property”, default=1.0, min=0.5, max=2.5)

To (greatly) simplify a piece of code (and avoid manually typing over a hundred properties) I would like to do just like the above but from a string (pulled from an array of 100+ strings). Example:

bpy.types.Scene[“MyPropertyName”] = FloatProperty(name=“Test Property”, default=1.0, min=0.5, max=2.5)

Is there a way to do that? That would be so useful!

ID properties can be created “on the fly”. Name, description, default etc can be added using the ‘_RNA_UI’ key.


import bpy
context = bpy.context
scene = context.scene

scene['_RNA_UI'] = scene.get('_RNA_UI', {})

scene["MyProp"] = 1.0
scene['_RNA_UI']["MyProp"] = {"name": "My Prop",
                              "description": "ToolTip",
                              "default": 0.0,
                              "min": 0.0,
                              "max":1.0}


Hi batFINGER!

Thank so much for taking the time! The answer is more complex than I had thought! I don’t think I would have figured this one out!

Thanks man!! :slight_smile:

Hi batFINGER!

Thank you again for the assistance!

While I’ve been able to create custom properties from a string name with the code you provided (can see them in the scene custom properties rollout), I unfortunately cannot use these properties in panel widgets!

For example if I create a property the standard way with code like:

bpy.types.Scene.MyProp = FloatProperty(name=“MyProp”, default=100, min=50, max=2500)

I can manipulate it in a UI panel with code like this:

class Panel_Test(bpy.types.Panel):
bl_space_type = “VIEW_3D”
bl_region_type = “TOOLS”
bl_context = “objectmode”
bl_label = “Test Panel”

def draw_header(self, context):

layout = self.layout
layout.label(text="", icon=“WORLD”)

def draw(self, context):

layout = self.layout
col = layout.column(align=True)
col.prop(context.scene, “MyProp”)

However if I invoke your code to create “MyProp” (again both will show in scene custom properties) then the property won’t show in the panel and I’ll get a warning “rna_uiItemR: property not found: Scene.MyProp”

Any clue why?

Thanks again for the help!!

For ID props


layout.prop(scene, '["MyProp"]')

Ah thanks man! You rock :slight_smile: