Login | Register 
Products Applications Downloads Features Wiki forum Store
 

Python To Touch

Helpful techniques for working with TouchDesigner. Answers only, no questions.

Python To Touch

Postby Achim » Fri Oct 10, 2008 3:24 am

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
Code: Select all
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:
Code: Select all
mySocket.send('names foo bar \0')

creates two channels named "foo" and "bar".


Code: Select all
mySocket.send('slice 1 2 \0')

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


Code: Select all
mySocket.send('script confirm fromPython \0')

will bring up a dialog box


Finally, you need to close the socket
Code: Select all
mySocket.close()


not sure if you need to send this before closing the socket
Code: Select all
mySocket.send('disconnect \0')
User avatar
Achim
 
Posts: 1510
Joined: Wed Nov 14, 2007 12:52 pm

Return to Techniques

Who is online

Users browsing this forum: No registered users and 1 guest