5
$\begingroup$

I'd like the contents of this custom editor panel to persist with the file.

I can't seem to get my PropertyGroup or even a StringProperty to save with the blend file.

class PG_mypg(bpy.types.PropertyGroup):
    custString = bpy.props.StringProperty(name="custString")

bpy.utils.register_class(PG_mypg)

# this adds it but it doesn't persist in the file
bpy.types.WindowManager.myPanelSettings = bpy.props.PointerProperty(type=PG_mypg)

# even this one doesn't save either
bpy.types.WindowManager.myCustString = bpy.props.StringProperty(name="customString")

Note that I want this to be set for my window, not per object.

$\endgroup$
1
  • $\begingroup$ Would it be possible to add an empty object type that isn't visible in the 3d view? This is how I would do it in unity3d. $\endgroup$
    – Ben L
    Commented Apr 10, 2014 at 14:50

1 Answer 1

6
$\begingroup$

Custom properties to the bpy.types.WindowManager type don't serialize to .blend
(as if options={'SKIP_SAVE'} was set).

Your options are to use

  • bpy.types.Scene, but you will need to chose one scene instance to store the actual properties, and if that scene is deleted, they will be gone
  • Serialization: serialize your data to a string and make it the text body of a new text datablock. Give the datablock a name that starts with a dot, e.g. .my-data, to hide it in the interface. It is less likely to be removed like a scene this way.
  • AddonPreferences or saving to a custom configuration file - if the data is relevant to not just the current .blend, but the local Blender installation
$\endgroup$
4
  • 5
    $\begingroup$ The comment about 'SKIP_SAVE' isnt really correct, SKIP_SAVE is for operators not to reuse previous settings. $\endgroup$
    – ideasman42
    Commented Apr 10, 2014 at 3:58
  • $\begingroup$ I like the suggestion for AddonPreferences but it doesn't solve this problem in particular. $\endgroup$
    – Ben L
    Commented Apr 10, 2014 at 17:27
  • $\begingroup$ @ideasman42: Interesting, this isn't documented anywhere it seems. BenL: That's right, it really depends on the use case. $\endgroup$
    – CodeManX
    Commented Apr 10, 2014 at 17:33
  • $\begingroup$ I'm just going to add a utility to copy or reference the data block from one scene to another. That is the hack that seems the least hacky. $\endgroup$
    – Ben L
    Commented Apr 16, 2014 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .