PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
How-to
Scripts
  • Overview
  • Tutorial
  • Reference
Layout and positioning
  • CELL
  • TABLE
Language basics
  • SKIN
  • DUMMY
  • INCLUDE
  • INCLUDE_ONCE
  • DEFINE
  • UNDEFINE
  • VARIABLE
  • LOCAL_VARIABLE
  • TEMPLATE
  • TEMPLATE_INNER_CONTENT
  • TEMPLATE_UNLOAD
  • REPEAT
Text widgets
  • TEXT
  • TEXT_FIELD
  • TEXT_EDIT_BOX
  • TOOLTIP
  • PARAM_TEXT
  • PARAM_TEXT_CONTROL
  • PARAM_TEXT_EDIT_BOX
  • PARAM_TOOLTIP
Image widgets
  • IMAGE
  • IMAGE_ACTION_BUTTON
  • IMAGE_GROUP_BOX
  • IMAGE_PARAM_BUTTON
  • IMAGE_PARAM_KNOB
  • IMAGE_PARAM_LINEAR_METER
  • IMAGE_PARAM_MENU_BUTTON
  • IMAGE_PARAM_METER
  • IMAGE_PARAM_SLIDER
  • IMAGE_PARAM_TOGGLE_SWITCH
  • XYZ_IMAGE_PARAM_JOYSTICK
Invisible controls
  • INVISIBLE_ACTION_BUTTON
  • INVISIBLE_PARAM_BUTTON
  • INVISIBLE_PARAM_KNOB
  • INVISIBLE_PARAM_MENU_BUTTON
  • INVISIBLE_PARAM_SLIDER
  • INVISIBLE_PARAM_TOGGLE_SWITCH
  • XY_PARAM_PAD
  • XY_ZOOM_SELECT_PAD
  • XYZ_PARAM_SCRATCH_PAD
  • XYZ_PARAM_CLICK_PAD
Drawing, curves & 3D
  • CANVAS
    • Graphics API
  • svg
  • CURVE_GRAPH
  • XY_CURVES_GRAPH
  • GRID
  • RULER
  • COLOR_SCALE
  • VIEW_3D
  • COLOR_SURFACE_3D
  • GRID_3D
  • GL_OBJECT_3D
    • OpenGL Cheat Sheet
  • SURFACE_COLORMAP_2DPLOT
Miscellaneous
  • SCRIPT
  • WIDGET
  • KUIML_WIDGET
  • POPUP_MENU
  • MENU_ITEM
  • MENU_SEPARATOR
  • FILE_SELECT_MENU
  • SYSTEM_ACTION_BUTTON
  • SYSTEM_PARAM_CHECKBOX
  • SYSTEM_PARAM_DROPDOWN_LIST
  • WINDOW
  • LOAD_FONT
Data model
  • STRING
  • PARAM
  • FORMULA_PARAM
  • PARAM_ANIMATOR
  • ACTION
    • Built-in action types
  • TIMER
  • ACTION_TRIGGER
  • CURVE
  • FORMULA_CURVE
  • CURVE_FROM_PARAM_OVER_TIME
  • SURFACE
  • FORMULA_SURFACE
  • SURFACE_FROM_CURVE_OVER_TIME
  • GROUP
Links and commands
  • PARAM_LINK
  • PARAM_MULTI_LINK
  • PARAM_CONNECTION
  • PARAM_TO_STRING_LINK
  • STRING_LINK
  • STRING_MULTI_LINK
  • CURVE_LINK
  • CURVE_MULTI_LINK
  • SURFACE_LINK
  • REQUIRED_OBJECTS
  • EXPOSED_OBJECTS
  • PERSISTENT_OBJECTS
Common attrubutes
  • For all elements
  • Widgets
  • Param Widgets
  • Param Controls
  • Param Info Viewers
  • Text Widgets
  • Surface Viewers
  • Curve Viewers
  • Images
  • 3D Objects
Additional information
  • All attributes
  • Attribute types
  • Cursors
  • Math formulas
  • Scripting
    • Built-in addons
  • User experience
  • Errors and solutions
  • Built-in variables
  • Runtime model
  • Parameters mapping
  • Script converter
  • LetiMix
KUIMLReferenceScriptingBuilt-in addons
August 23, 2025

Built-in addons

AngelScript basics

Math functions * | Script Arrays | Strings (string functions) | File | Dictionary | Filesystem | Datetime

* Math uses double instead of float, and has additional exp function. 

StopWatch

StopWatch watch;
watch.Start();
double elapsed = watch.elapsed;
watch.Stop();

A high precision stop watch to measure elapsed time. Elapsed time is in milliseconds, but its precision depends on the platform (usually precision should be close to a few microseconds).

  1. <!-- demo string -->
  2. <STRING id="demo_string" />

  3. <!-- see the value of a string -->
  4. <TEXT_EDIT_BOX string_id="demo_string" width="200" />

  5. <!-- demo action -->
  6. <ACTION id="do_run" type="Script" script=" 

  7. /* create an start StopWatch */
  8. StopWatch watch;
  9. watch.Start();

  10. /* run a system shell command */
  11. system(&quot;sleep 1&quot;);

  12. /* get elapsed time in milliseconds */
  13. double elapsed = watch.elapsed;
  14. watch.Stop();

  15. /* output to a string */
  16. demo_string = &quot;Elapsed: &quot; + elapsed;
  17.  " name="Run" requires="demo_string" />

  18. <!-- button to run an action -->
  19. <SYSTEM_ACTION_BUTTON action_id="do_run" />

XMLNode

Class and enum:

class XmlNode Reference type that describes a node in an Xml tree structure (DOM). 
  XmlNodeType type type of node (see below)
  string name name of the node
  dictionary & attributes attributes of element nodes
  array<XmlNode> & childNodes children nodes
enum XmlNodeType { kXmlElement, kXmlComment, kXmlText } Types of nodes: Element node, Comment node, Text node

Functions:

XmlNode XmlParseFile (const string &file) Parse an Xml file and build the corresponding DOM tree structure (returns null if failed).
XmlNode XmlParse (const string &str) Parse a string containing Xml and build the corresponding DOM tree structure (returns null if failed).
bool XmlWriteFile (const XmlNode &in xml, const string &file) Write an Xml DOM into a file. Returns false upon failure.
bool XmlWrite (const XmlNode &in xml, string &str) Write an Xml DOM into a string. Returns false upon failure.

An example of reading and parsing an XML file.

  1. <!-- script function to go through xml file -->
  2. <!-- note we use script='...' (single quotes) to avoid &quot; -->
  3. <SCRIPT script='
  4. /* read the XML file and get root node */
  5. void parseXMLFile() {
  6. auto node = XmlParseFile("$_FILE_$");
  7. if (@node == null) {
  8. sout = "Failed to read a file via XmlParseFile:";
  9. } else {
  10. sout = "Succeeded to read a file via XmlParseFile.\n$_FILE_$\n";
  11. scanXMLData(node);
  12. }
  13. }
  14. /* print node values (recursively) */
  15. void scanXMLData(XmlNode @ node, int depth = 0) {
  16. /* create indentation */
  17. string indent = "";
  18. for(int n=0;n&lt;depth;n++) { indent += " "; }
  19. /* output node data */
  20. if (node.type == 1) indent += "//"; /* for comments */
  21. sout += "\n" + indent + node.name + "" + ((node.type == 0) ? "": ((node.type == 1) ? "(Comment)" : "(Text)")) + "";
  22. /* see if we have attributes */
  23. int attrs_qty = node.attributes.getSize();
  24. if (attrs_qty > 0) {
  25. sout += " ("+attrs_qty+")";
  26. auto keys = node.attributes.getKeys();
  27. for(uint i=0;i&lt;keys.length;i++){
  28. sout += " | "+keys[i] + "=" + string(node.attributes[keys[i]]);
  29. }
  30. }

  31. /* go to children (recursively) */
  32. if (node.childNodes.length > 0) {
  33. for(uint i=0;i&lt;node.childNodes.length;i++) {
  34. scanXMLData(node.childNodes[i], depth+1);
  35. }
  36. }
  37. }
  38. ' />

  39. <!-- auto run on GUI load -->
  40. <ACTION_TRIGGER event_id="window.loaded.value_changed" condition_formula="window.loaded==1" script="parseXMLFile();" />

  41. <!-- demo string -->
  42. <STRING id="sout" default="Ready to run." />

  43. <!-- include textwidget (LM Skin only) -->
  44. <INCLUDE file="$EXTENSIONS_DIR$tw.inc" />
  45. <TW_LOG string_id="sout" width="500" height="200" trim_spaces="" scrollpos="0" />

  46. <!-- demo action -->
  47. <ACTION id="do_run" type="Script" script=" 
  48. parseXMLFile();
  49.  " name="Run" requires="sout" />

  50. <!-- button to run an action -->
  51. <SYSTEM_ACTION_BUTTON action_id="do_run" />

Unicode support (utf8)

Extensions to the scripting engine to deal with unicode strings (utf8)

Class utf8::iterator

class utf8::iterator (const string &iString)
class utf8::iterator (const iterator &iter)

  void operator= (const iterator &iIter)
  string first () positions the iterator at the first character in string and returns it (or empty) 
  string last () positions the iterator at the last character in string and returns it (or empty)
  string next (uint count) moves to the next character in string and returns it (or empty)
  string previous (uint count) moves to previous character in string and returns it (or empty)
  int index () returns the current position in the string (in bytes, NOT characters)

(Experimental) utf-8 iterator. Provides methods to navigate in unicode strings (all strings in KUIML are using utf-8 encoding).

Functions for Utf8

bool utf8::isValid (const string &in) returns true if the string contains valid utf8 characters.
string utf8::replaceInvalid (const string &in) replace invalid utf-8 character sequences in string by a special question mark character.
uint utf8::length (const string &in) returns the number of utf-8 characters in string (different from string length)

Using these class and function you can write your own functions to correctly process utf8 strings.

  1. <!-- demo string -->
  2. <STRING id="demo_string" />

  3. <!-- see the value of a string -->
  4. <TEXT_EDIT_BOX string_id="demo_string" width="400" />

  5. <!-- create a script function that uses utf8 iterator class -->
  6. <SCRIPT script=" 
  7. /* cut substring from a string by chars (not bytes) */
  8. string utf_substr(string s, uint start_char, int chars_to_cut = -1) {
  9. /* remove invalid chars (not utf8 compatible) with ? */
  10. s = utf8::replaceInvalid(s);

  11. /* create utf8 iterator and go to start character */
  12. utf8::iterator t(s);
  13. t.first();
  14. t.next(start_char);

  15. /* get byte position of current char */
  16. int startbyte = t.index();

  17. /* get the end byte position */
  18. if (chars_to_cut > 0) {
  19. t.next(chars_to_cut);
  20. } else if (chars_to_cut &lt; 0) {
  21. t.last();
  22. }
  23. int endbyte = t.index();

  24. /* cut the string with regular function */
  25. return s.substr(startbyte, endbyte-startbyte);
  26. }
  27.  " />

  28. <!-- demo action -->
  29. <ACTION id="do_run" type="Script" script=" 

  30. /* a string with utf-8 */
  31. string s = &quot;Слава Юрию Гагарину!&quot;;

  32. /* call a function we've crafted */
  33. demo_string = utf_substr(s, 11, 7);

  34. /* get utf8-length of the original string */
  35. demo_string += &quot; | original length: &quot;+ utf8::length(s);

  36. /* get utf8-length of the original string */
  37. demo_string += &quot; | isValid: &quot;+ utf8::isValid(s);

  38.  " name="Run" requires="demo_string" />

  39. <!-- button to run an action -->
  40. <SYSTEM_ACTION_BUTTON action_id="do_run" />

rand

double rand(double min = 0, double max = 1)

Generates a random number between min and max.

  1. /* get a 'random' value between -10.5 .. 10.5 */
  2. double value = rand(-10.5, 10.5);

system

int system(const string & command)
int system(const string & command, string & output)

Executes "command" using the system shell and waits for the command to finish. Returns the result of the command; (optional) returns the output as a string

  1. <!-- demo string -->
  2. <STRING id="demo_string" />

  3. <!-- see the value of a string -->
  4. <TEXT_EDIT_BOX string_id="demo_string" width="100" />

  5. <!-- demo action -->
  6. <ACTION id="do_run" type="Script" script=" 

  7. /* if we don't need text output */
  8. int result = system(&quot;mkdir /Users/letimix/A_TEST&quot;);

  9. /* to get output as a string (into Kt::String here */
  10. system(&quot;cd /Users/letimix; ls&quot;, demo_string);

  11.  " name="Run" requires="demo_string" />

  12. <!-- button to run an action -->
  13. <SYSTEM_ACTION_BUTTON action_id="do_run" />

The 'system' command is powerful, however it waits till it's finished, which makes the GUI "freeze" while it's running. So be careful with it, especially for possibly long-running operations (like curl, etc). Speaking of curl, for internet access see ACTION type="LoadURL" which can be executed asyncronously.

getObjectById (experimental)

ref@ getObjectById(const string &in)

Get a handle to a KUIML object by id. Can be useful to access objects that you're not sure exist during the runtime. Don't forget that object should be exposed to scripts (using EXPOSED_OBJECTS or requires attribute). This is experimental and can change, use at your own risk.

  1. <!-- demo widget and demo param -->
  2. <WIDGET id="demo_widget" background_color="#DD0000" width="20" height="10" />
  3. <PARAM id="demo_param" min="0" max="100" default="0" />

  4. <!-- see the value of param -->
  5. <PARAM_TEXT_CONTROL param_id="demo_param" />

  6. <!-- demo action -->
  7. <ACTION id="do_run" type="Script" script=" 

  8. /* change KUIML PARAM value if it exists */
  9. auto obj = getObjectById(&quot;demo_param&quot;);
  10. if (obj != null) {
  11. auto param = cast&lt;Kt::Param@>(obj);
  12. if (param != null) param = 50 + rand(-10,10);
  13. }

  14. /* can instead of auto use classes ref@ and Kt::Param@ */

  15. /* change WIDGET.width if it exists */
  16. ref@ obj2 = getObjectById(&quot;demo_widget.width&quot;);
  17. if (obj2 != null) {
  18. Kt::Param@ ktP = cast&lt;Kt::Param@>(obj2);
  19. if (@ktP != null) ktP = rand(1,100);
  20. }

  21. /* can write it a bit shorter not checking for null before cast */

  22. /* change WIDGET.background_color if exists */
  23. Kt::Param@ red = cast&lt;Kt::Param@>(getObjectById(&quot;demo_widget.background_color.r&quot;));
  24. if (@red != null) red = rand(0,1);

  25. /* the next one will not work, cause object is not exposed (see 'requires' and EXPOSED_OBJECTS) */

  26. /* try change WIDGET.height */
  27. Kt::Param@ heightParam = cast&lt;Kt::Param@>(getObjectById(&quot;demo_widget.height&quot;));
  28. if (@heightParam != null) heightParam = rand(1,10);

  29.  " name="Run" requires="demo_widget.width;demo_widget.background_color.r;demo_param" />

  30. <!-- button to run an action -->
  31. <SYSTEM_ACTION_BUTTON action_id="do_run" />

See AngelScript Object Handles and Expressions (Type conversions).

Graphics

KUIML exposes a Kt::Graphics class. See more in CANVAS and Graphics API.


Comments

Please, authorize to view and post comments.

2020 - 2026 © Site by LetiMix · Donate  |  Plug'n Script and KUIML by Blue Cat Audio