ALTIUM SCRIPTING AND USING THE API

Reading And Writing To Files

Date Published:
Last Modified:

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:

var myIniFile
myIniFile = TIniFile.Create(fileName)

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

Reading And Writing To INI Files

Booleans

You can write a boolean-based data point using:

iniFile.WriteBool category, key, trueFalse

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

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

Dim myBool
myBool = myIniFile.ReadBool(category, key)

Strings

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

iniFile.WriteString category, key, value

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

[category]
key=value

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

value = iniFile.ReadString category, key

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


Like this page? Upvote with shurikens!

Tags:

    comments powered by Disqus