Memorize a variable for all SketchUp sessions

Hello :slight_smile:

Is it possible to create a variable or an attribute that remains in memory for all SketchUp sessions?

For example:
Sketchup.active_model.set_attribute (‘att1’, ‘Last’, ‘1’)

This method creates an attribute for a project only.

I want to find a way for the attribute or variable to persist in all new SketchUp projects.

Thank you in advance for your help.

Manuel

You can use:
Sketchup.read_default and Sketchup.write_default


2 Likes

Hello Guy,

Thanks for these informations.

How to create the file “INI” and in which directory should it be put?

From a “RB” script how can find and modify the variable of the file “INI”?

Thank you

Manuel

Le ven. 22 févr. 2019 à 14:29, Guy Wydouw via SketchUp Forum sketchup@discoursemail.com a écrit :

Don’t worry about the ‘INI’ file.
The wording in that section is somewhat out of date.
It is also plain wrong in some places !

Sketchup.read_default and Sketchup.write_default methods are ways of writing and reading your own values globally, stored with SketchUp itself rather than your model or session.
They are saved in various ways depending on your OS and SketchUp version - registry/plist and more recently json files in the user’s tree…

The ‘writing’ simply has three arguments [similar to attribute dictionaries]
Sketchup.write_default(section, key, value)

The ‘reading’ has three*** [again similar to attribute dictionaries]
value = Sketchup.read_default(section, key, default_value)

***If ‘default_value’ is omitted and the key is not defined it will then return nil

The ‘section’ is your own tool’s ‘name’ string.
The ‘key’ is your own named-key string.
The ‘value’ can be most of the usual formats available to attribute dictionaries.
Although the values are always stored as ‘text’ strings, the reading process should convert them back to their original format - so 1.234 writes >>> “1.234” then it reads >>> 1.234

@contact.manuelbarros Your section name needs to be globally unique. This means you should prefix with your company or author name, then an underscore (_) and then the name of your plugin.

Example: "EmpresaBarros_TrabajoIngenioso"

This is because the JSON text files are shared and used by all plugin authors / companies.

3 Likes

Thank you for this information and advice!
Everything works as I want. :wink: