Reading And Writing To Files

Overview

You have the ability to write to and read from files inside Altium scripts. This can be useful for saving user configuration data that persists between each time the script is run, or providing input/output data for a particular script that needs to interact with the operating system.

The objects of interest are TIniFile.

TIniFile is great for storing category-key-value (or just key-value) information.

INI Files

Creating An INI File

You can create an INI file by using:

 where fileName is an absolute path string to the file you wish to create (e.g. C:\Users\MyUser\test.ini).

Note that “Create” is a little misleading. If the file already exists, this function performs more like “open for editing”. It does not delete any information already present in the INI file.

Reading And Writing To INI Files

Booleans

You can write a boolean-based data point using:

 where category and key are strings, and trueFalse is a boolean.

You can read a boolean-based data point from an INI file using:

 …

Strings

Similarly to writing a boolean, you can write a string-based data set using:

 where category, key and value are all strings. This will create an INI file which looks like this:

 You can read a data set from an INI file using:

 Have a look at the file UserData.vbs in the AltiumScriptCentral repo on GitHub for INI file read/write examples.