Custom Property#

Add a new custom Property to the parent Node.

import tosclib as tosc

if __name__ == "__main__":

    root = tosc.load("docs/demos/files/test2.tosc")
    parent = tosc.ElementTOSC(root[0])

    # Set the property to the parent node, not the root node.
    prop = tosc.Property("s", "CustomProperty", "Craig")
    parent.createProperty(prop)

    print("Added Property: ")
    parent.showProperty("CustomProperty")

    tosc.write(root, "docs/demos/files/customProp.tosc")

Then you can access that Property in Touch OSC Editor with .lua like this:

--This is lua code inside the touch osc editor--
function onValueChanged(key, value)
    if key == "touch" and self.values.touch == true then
        print(self.parent.CustomProperty)
        self.parent.CustomProperty = self.parent.children.label2.values.text
    end
end

Demo Files:

GIFS

  1. Call script that changes the Custom Property, then call another one that sets the label text to the Custom Property.

../_images/tosclib-property1.GIF
  1. Save and close the template. Then load it again and you’ll see the label text remains, as it sets its value to the Custom Property on init.

../_images/tosclib-property2.GIF
This is the lua code in the label#
function init()
    self.parent.children.label3.values.text = self.parent.CustomProperty
end

function onValueChanged(key, value)
    if key == "touch" and self.values.touch == true then
        print(self.parent.CustomProperty)
        self.parent.children.label3.values.text = self.parent.CustomProperty
    end
end