Dynamic PropertyGroups / Saving Custom Data

Hello Blender Coders/Blender Community!

I need some help with Blender Python. Here is what I want to achive:
I am integrating a game engine into Blender to be able to run and edit engine content directly from within Blender. Basically the point where I’m stuck is, that every bpy.types.Object is supposed to have a list of so called “Components”, for which I want to be able to edit the properties in a Panel. There are many different Component types (31 currently) and all have different attributes, so my idea was to generate the UI for those from the properties.

What I can do:

  • Dynamically create a bpy.types.PropertyGroup from a Component’s attributes
  • Automatically create UI from bpy.types.PropertyGroup (I did this myself, but does anybody know a build-in function to do this?)

What I cannot do, but need to do:

  • Add the dynamically created bpy.types.PropertyGroup subclass for the Components to a bpy.types.PropertyCollection.
  • Either save custom data to the .blend without using properties
  • OR save/load extenernal data whenever blender loads/saves a .blend file [solved via load and save handlers]

If anybody knows how to do one of those things, I’d be glad if you could give me a hint, I’ve been trying to figure this out for ~8 hrs now. I hope I didn’t reach the Python API’s limits here.

Thank you in advance!

Did you try Custom Properties panel yet?

You mean creating a panel for custom properties? Sure, I’m doing that already and it’s contents are more or less dynamically generated for whatever properties a ComponentItem(PropertyGroup) has. But I cannot add custom properties to make them discoverable via keys() for example…

The Custom Properties Panel corresponds to ID-Properties, am I right? http://wiki.blender.org/index.php/Doc:2.6/Manual/Extensions/Python/Properties

I can only assign Int, Float and String and Lists of those types, if I understood correctly. It would be great to be able to use color pickers, vectors etc aswell.

Okay, I actually got this to work. But with a unbelievably dirty hack :wink:

In Object I added a CollectionProperty which contains ComponentItemProperty items. I dynamically create a PropertyGroup for each component type I come by, if I haven’t done so already, and add it to ComponentItemProperty as a PointerProperty. I also store a String in ComponentItemProperty for which dynamically created class it uses. Obviously, this might store (worst case) 30 unused PropertyGroups in the .blend file. But until there are better solutions, this will have to do.
With the String I can retrieve the PropertyGroup for the ComponentItemProperty items, and generate their individual UIs.

I found a way better way now. Basically for every ComponentType I create a CollectionProperty for the dynamically created PropertiesGroup. Was a little more code to implement, but it works now, and it isn’t quite as horrifically inefficient.

Just in general: Is there a way to draw ui without the builtin properties?