Python and Pipe In Chop

   4258   4   2
User Avatar
Member
4 posts
Joined: March 2014
Offline
Hello,
I have been looking into using the Pipe In Chop to get some data from Python into houdini using a pipe file.
I have only found a small example here: http://whoudini.blogspot.co.nz/2010/02/ok-i-know-i-promised-you-something-else.html [whoudini.blogspot.co.nz]

I am trying to write to a fifo file similar to here, but I am not getting any info through my pipe in.

import time
from struct import pack

def sendReset(fifo):
m = pack('cccccccc',esc,nul,esc,nul,esc,nul,esc,nul)
fifo.write(m)
fifo.flush()

def sendCurrentValues(fifo, channelCount, samples):
commandType = 1
m = pack('>ii', commandType,channelCount)
fifo.write(m)
for i in range(channelCount):
d = pack('>f', samples)
fifo.write(d)

esc = chr(170)
nul = chr(0)

PATH = ‘/tmp/python.pipe’
fifo = open(PATH,'w')
print ‘file open for writing: ’+ PATH
while True:
sendReset(fifo)
channelCount = 1
samples =
sendCurrentValues(fifo, channelCount, samples)
print(samples)
fifo.flush()
time.sleep(0.03)

Would love to see some working examples?
User Avatar
Member
7733 posts
Joined: July 2005
Offline
http://forums.odforce.net/topic/15067-pipe-in-fifo-file/?p=110438 [forums.odforce.net]
User Avatar
Member
4 posts
Joined: March 2014
Offline
Thanks Edward,

Though I had tried that one, but I think I had the same problem as him at school.

Got it working on my home computer though.
User Avatar
Member
7 posts
Joined: April 2015
Offline
So… you got it working??

I'm having this same problem. Not a lot of people have been using the pipe in node it seems.
Could you share some of your code or something to guide me through the setting up an external Python node to communicate with Houdini via Pipe In??

If you also got Pipe Out working that would be great as it's something I also need.

Thanks!
Francisco.
User Avatar
Member
4 posts
Joined: March 2014
Offline
Hey,

In the end I used the network function in the PipeIn chop, instead of the file option. This was because I wasn't quite getting my head around the FIFO stuff. Also the network function allows you to send info from another computer. Could be a fun project hooking up multiple computers.

Any way here is the real basic Python I used to test out the connection.
import time
import socket
from struct import pack

def sendReset(conn):
conn.send(pack('cccccccc', esc, nul, esc, nul, esc, nul, esc, nul))

def send(conn, value):
for ch in value:
if ch == esc:
conn.send(ch)
conn.send(ch)

def sendCurrentValues(conn, channelCount, samples):
commandType = 1
conn.send(pack('>Q', commandType))
conn.send(pack('>Q', channelCount))
for s in samples:
send(conn, pack('>d', s))

esc = chr(170)
nul = chr(0)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 5204))
s.listen(1)
conn, addr = s.accept()
print ‘connection established’

while True:
sendReset(conn)
channelCount = 3
samples =
sendCurrentValues(conn, channelCount, samples)
time.sleep(0.3)

This just sends three values through.

Here is what came out of this project http://everittcreative.me/gallery/03houdini.html [everittcreative.me]
switched to processing from python, purely for the Kinect libraries. Same strategy of sending the data though.
  • Quick Links