# Author: Malcolm Kesson (2007) proc sendToMaya { path } { set sock [socket "localhost" 2222] set mel_command "source \"$path\";" puts $sock $mel_command flush $sock puts $sock "" } proc readFile { path } { set data "" set filein [open $path r] while {[eof $filein] != 1} { append data [gets $filein] append data "\n" } close $filein return $data } proc _sendToMaya { host port path } { set sockOut [socket $host $port] set data "" puts "opening file" set fileIn [open $path r] # Grab all the data while {[eof $fileIn] == 0} { lappend data "[gets $fileIn]\n" } puts "read [string length $data] bytes" close $fileIn # Send the data - possibly in chunks set output "" foreach line $data { append output $line if {[string length $output] > 2048} { puts "sending chunk" puts $sockOut $output flush $sockOut puts $sockOut "" puts "reply [gets $sockOut]" #puts $sockOut "" set output "" after 10 } } if {[string length $output] > 0} { puts "sending extra" puts $sockOut $output flush $sockOut gets $sockOut #puts $sockOut "" } }