How to save user settings across sessions?
-
I'd like users of my script to be able to set some parameters that affect the behavior of the script, and I'd like those to be saved across sessions. What's the best way to accomplish that? Can you manipulate the registry from within a ruby script? (Windows specific, anyway, so not the best option). A pointer to an example script would be fine. Thanks, CB.
-
What's the best way depends on your needs. Some people need the Windows Registry, some people like files (ini, xml). If you want to use files, you have to implement the algorithm on your own or load the third party Ruby modules for these jobs like REXML.
azuby
-
I recommend you investigate the Sketchup class. It should prove enlightening on this point.
-
I See. I assume you are referring to read_defaults and write_defaults? Does this work across platforms? I don't see where you specify the file name, so it must use a central database that the whole sketchup application uses? Thanks, Rick - I'll experiment. CB.
-
Yes, it works across platforms. In Windows, it goes into the Registry. On the Mac... I don't know. Perhaps the .plist file. I haven't snooped around enough on the Mac yet.
Windows has issues with certain characters whne saving to the Registry, so test your values that get saved and retrieved. You may need to encode them somehow.
Todd
-
That worked great for me, guys. Thanks a lot. Rick, I found a good example in your dashed lines script. I noticed that you had dropdowns in your inputbox, and figured out how you did it (not documented in the SU Ruby docs?). I have several Y/N options, but I could only get one drop-down box to work on a given inputbox. Is that a known limitation, or am I doing something wrong? CB.
-
Hi Clark. There is a dropdowns.rb script floating around somewhere that shows how to do mutiple dropdowns in a given dialog. (I wrote it, and dashed lines too!) Check the Didier's Depot, or the old SU Ruby Forum.
Todd
-
Alternativelyn you could use attributes to store data within the SKP. That's the best way IMHO to save parameters (platform independent).
Regards, -
Todd: Thanks for the tip, and sorry for assuming that what I found at smustard would be Rick's. I use Dashed lines all the time. Thanks for that, too. CB.
-
I use attributes to store data in a model when it's relevant to the model (like in my ToDoList plugin). But something that would be comparable to a "global" setting is best (IMO) put into something external - registry/ini file/other text file.
Advertisement