0

Is there a way for Blender to remember the value that the user last used?

Once I quit the application, the Blender GUI values are reset. But,I want to display the value entered by the user at the last startup on the GUI as it is.

If I save that value, is it best to create a text file on the user's PC and save it?

Autodesk Maya has a command called "optionVar" that I could use to save the value. Is there something close to that in Blender?

The code is partially shown below. I created a text field with default values in code like this:

class QueryProps_stringProperties(bpy.types.PropertyGroup):
testText = "testText"
query_testText: bpy.props.StringProperty(default=testText)


class Test_PT_Panel(bpy.types.Panel): blidname = "Test_PT_Panel" bl_label = "Test Panel" bl_category = "Test" bl_space_type = "VIEW_3D" bl_region_type = "UI"

def draw(self,context):
    sce = context.scene
    props_stringProp = sce.QueryProps_stringProperties

    layout = self.layout

    row = layout.row()
    row.label(text="testText")
    row.prop(props_stringProp, "query_testText", text="")

What I'm showing is a UI that doesn't want to store information in a .blend file, it retains its value no matter what scene you open at any time.

taichi
  • 398
  • 4
  • 16
  • 1
    Which parts of the GUI are you referring to? Is this something owned by an addon you've written, or something native to Blender? – Chris Hayes Dec 20 '20 at 21:10
  • It means what the add-on I wrote owns. – taichi Dec 20 '20 at 22:22
  • 2
    If you're using PropertyGroups, those values are typically persisted in the .blend file without any special effort. Can you share some code where you're having this issue? – Chris Hayes Dec 21 '20 at 02:49
  • It's a useful feature I didn't know about. But my code doesn't seem to save the value. It may be because I set the initial value in the code. I added the code to the question. – taichi Dec 21 '20 at 04:52
  • Have a look into the template from: How to create a custom UI?... and you'll see that the values are stored per file... (registered per scene). In the example given you are just overriding the value each time the add-on code gets registered. – brockmann Dec 21 '20 at 10:18
  • I read this and tried it, but it didn't work. I also restarted Blender after changing the value of Blender native, but I confirmed that the value was not saved. For example, if you change the value of Unit Scale to 1.01 and then restart Blender, Unit Scale will remain at 1.00. Is there an option inside Blender to save the value? – taichi Dec 23 '20 at 01:18
  • If I understand correctly from your last line, you want an addon GUI which remembers its last values regardless of which .blend file is open? That's pretty much the opposite of how PropertyGroups work, which could explain your trouble. – Chris Hayes Dec 23 '20 at 06:38

0 Answers0