How to save a user's (plugin-related) preferences?

This topic has been viewed 3804 times and has 4 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
shmuelzon
Posts: 14
Joined: Sun Dec 24, 2023 6:13 am
Country: Israel

How to save a user's (plugin-related) preferences?

Post by shmuelzon »

Hey,

I was wondering if there was some mechanism with which I can persistently save a few settings the user can modify within my plugin. I've seen the UserPreferences class but it has setters/getters only for the specific options SH3D supports.

Is there some generic tags, key-value-pairs or anything that a plugin can set that will be saved as a part of the SH3D project file?

Thanks in advance!
User avatar
Daniels118
Posts: 503
Joined: Wed Nov 17, 2021 9:04 pm
Country: Italy

Re: How to save a user's (plugin-related) preferences?

Post by Daniels118 »

The Home class allows to set custom properties.
shmuelzon
Posts: 14
Joined: Sun Dec 24, 2023 6:13 am
Country: Israel

Re: How to save a user's (plugin-related) preferences?

Post by shmuelzon »

Thanks, I believe you're referring to getProperty()/getNumericProperty()/setProperty()?

They seem to do the job, assuming I save the project file but setting a property doesn't seem to mark the project as modified so the user will be alerted that they need to save it. Is the plugin expected to call setModified() when a property's value changes?
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: How to save a user's (plugin-related) preferences?

Post by Puybaret »

Some properties are not so important to save like window size after resizing it. Some other properties should be saved and in that case, you should call [font=courier new]setModified[/font] method.
Prefer to use properties with a unique prefix to avoid any clash with future ones or properties managed by other plug-ins.

Note that these home properties are saved for a project, not for all projects like you seemed to want by speaking about "preferences". As you noticed, there are no [font=courier new]setProperty[/font] / [font=courier new]getProperty[/font] in [font=courier new]UserPreferences[/font] class at the moment, but can save additional data at the same place as where [font=courier new]preferences.xm[/font] file is saved if needed.
Emmanuel Puybaret, Sweet Home 3D creator
shmuelzon
Posts: 14
Joined: Sun Dec 24, 2023 6:13 am
Country: Israel

Re: How to save a user's (plugin-related) preferences?

Post by shmuelzon »

Hey, saving per home/project is good for my purposes.
Thanks for the explanations!
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest