Python To Touch

A simple example showing how to connect from python to touch via sockets

create a pipein CHOP and toggle the “Originate” and the “Allow Incoming Scripts” parameter on
then open the python command line application

type

import socket mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) mySocket.connect ( ( 'localhost', 7000 ) )
so now you have a connection to the touchin CHOP on port 7000

To actually sent data to touch, you have to follow the protocol detailed in
TouchDesignerPro.077\touch\docs\pipe\pipe_example\protocol.txt
Remember that you need to include a terminating null: \0

for example:

mySocket.send('names foo bar \0')

creates two channels named “foo” and “bar”.

mySocket.send('slice 1 2 \0')

will put a value of 1 into foo channel and 2 into bar channel

mySocket.send('script confirm fromPython \0')

will bring up a dialog box

Finally, you need to close the socket

mySocket.close()

not sure if you need to send this before closing the socket

mySocket.send('disconnect \0')