Announcement

Collapse
No announcement yet.

Python Scripting to Viz Engine

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python Scripting to Viz Engine

    Has anyone used python scripting to connect to a Viz Engine to feed data? I saw an example but cant figure out how it works.

  • #2
    Shotski2 Hello, yes it is possible, I did it as a test, and I was able to change text for specific containers, I was parsing an xml file, extracting info from the xml and setting text or images depending on what the xml info was.

    I hope this is of some help, good luck


    Code:
    def talkToViz():
        #This is a variable I used in another part of the code
        global currentSponsorImage
    
        ## Create a TCP/IP socket
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        
        # Connect the socket to the port where the server is listening
        
        # this is the artist machine, where I was testing
        server_address = ('192.168.5.25', 6100)
        
        # this is the ticker engine, this is to confirm I could talk to other engines
        #server_address = ('192.168.5.12', 6100)
        
        #print >>sys.stderr, 'connecting to %s port %s' % server_address
        sock.connect(server_address)
        
        #Commands I was sending to the different engines
        #sock.send('0 RENDERER*FUNCTION*DataPool*Data SET tickerSponsorImage=' + str(currentHouseNumber) + '\0')
        #sock.send('0 MAIN_SCENE*TREE*$tickerSponsor*IMAGE SET IMAGE*KFMB_VER01/MASTER_CONTROL/TICKER_SPONSORS/' + 'name of the image' + '\0')
        
        # Next line is used to send a command to the engine, preffix and suffix were
        # declared at the top, this are just variable with viz commands, see the above line that starts, #soc.send...
        sock.send( vizCommandPreffix + currentSponsorImage + vizCommandSuffix)
        test to make sure the engine is reading what I'm sending
        print vizCommandPreffix, ' ', currentSponsorImage, ' ', vizCommandSuffix
        sock.close()
    
    main()

    Comment


    • #3
      Thanks Matzunaga, Do you have a scene i could use to see the workflow of this?

      Thanks,Shotski

      Comment


      • #4
        How do you run this script in Viz? or is it an external application?

        Comment


        • #5
          Shotski2 sorry I have not been able to respond, I was using python 2.X to run this, I am now running python 3.X and the script I send you doesn't work any longer, I have been trying to make it work but haven't been able to.

          The script when it worked I ran out of Textwrangler on a mac, I would just feed it some text via a variable and run the script which would connect to the artist engine, which was on air mode, and i was able to change the text on a container, or I could parse an xml and get the info I needed and then i would send it to the engine

          as per the scene, there was nothing special about it, the one thing you have to pay attention to is the hierarchy on your tree, which in the script would be the command you send to the engine for example
          #sock.send('0 MAIN_SCENE*TREE*$tickerSponsor*IMAGE SET IMAGE*KFMB_VER01/MASTER_CONTROL/TICKER_SPONSORS/' + 'name of the image' + '\0') in this case I am changing the image on a container from ('0 MAIN_SCENE*TREE*$tickerSponsor*IMAGE SET this is part of the command this IMAGE*KFMB_VER01/MASTER_CONTROL/TICKER_SPONSORS/ is the path to the image in my gfx hub

          name of the image, this is a variable

          and '\0') terminates the command

          With python 3.X and engine 3.8.1 I get the following error message

          TypeError: a bytes-like object is required, not 'str'

          but if I change the info I am sending to byte-object I get the following error

          TypeError: must be str, not bytes

          I don't know why it does not want to take either of the types I am sending

          if you find out why this thing is not working please post it

          Comment


          • #6
            I am trying to get the script to run through Notepad++ but it is not connecting to Viz. I don't get any errors but it is not connecting either. I'm at a loss.
            In the script below, i am just trying to connect to Viz artist in on-air mode but i get nothing. Any Ideas?

            def talkToViz():
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            server_address = ('10.55.14.104', 50007)
            sock.connect(server_address)
            sock.send('Hello, world')
            data = sock.recv(1024)
            sock.close()
            print ('Received', repr(data))

            Comment


            • #7
              So apparently in python 3 the way the data is received is as a binary code. I guess that changed from python 2 to python 3 for whatever reason. So i put a "b" for binary in from of the string 'Hello World'. The script below gets close but i get error in Viz once it connects. " ERROR: cannot read command from socket, code 10054". Almost there, just need to figure out this part. Any Ideas?

              import socket

              HOST = '10.55.14.104' # The remote host
              PORT = 6100 # The same port as used by the server
              socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              socket.connect((HOST, PORT))
              socket.send(b'Hello, world')
              data = socket.recv(1024)
              socket.close()
              print ('Received'), repr(data)

              Comment


              • #8
                I got it to work with this code:

                import socket

                HOST = '10.55.14.104' # The remote host
                PORT = 6100 # The same port as used by the server

                socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

                socket.connect((HOST, PORT))

                socket.send(b'0 MAIN_SCENE*TREE*$IMG*IMAGE SET IMAGE*DESIGNER_LIBRARY/Robert/berlin3')

                socket.close()
                #print ('Received'), repr(data)
                print ('Received')

                Comment


                • #9
                  Hello All,

                  Still having some issues with this script. I can get the information to populate from the xml and i can see it in python but i cant get the syntax to fill the containers. I get a socket error.

                  here is the script below. If anyone is a python/viz expert.

                  #Weather update from URL with Pyton
                  # Import necessary libraries
                  from xml.dom import minidom
                  import socket
                  import sys
                  import datetime
                  import time
                  from datetime import datetime
                  #'import urllib2
                  import urllib.request

                  #Var declaration
                  dayCounter = 1
                  highTempCounter = 1
                  weekReport = ()
                  dayReport = ()
                  dayCommandPreffix = '0 MAIN_SCENE*TREE*$day0'
                  highTempCommandPreffix = '0 MAIN_SCENE*TREE*$high_temp0'
                  vizCommandPreffix2 = '*GEOM*TEXT SET '
                  vizCommandSuffix = '\0'


                  def main():
                  readFeed()
                  printDays()
                  printHighTemps()

                  def readFeed():
                  global weekReport
                  global dayReport


                  readXMLfromURL = urllib.request.urlopen("http://xml.customweather.com/xml?product=current_extended&latitude=27.964157&longitude=-82.452606&client=vizrt_test&client_password=t3mp")

                  wxMiguelXML = minidom.parse(readXMLfromURL)
                  weekReport = wxMiguelXML.getElementsByTagName("report")[0]
                  dayReport = weekReport.getElementsByTagName("forecast")


                  def printDays():
                  for i in dayReport:
                  myDays = i.attributes["weekday"]
                  dayNames = myDays.value
                  daytalkToViz(dayNames)
                  #print (dayCommandPreffix)
                  print (dayNames)

                  def printHighTemps():
                  for j in dayReport:
                  myHighs = j.attributes["high_temp"]
                  dayHighTemps = myHighs.value
                  highTemptalkToViz(dayHighTemps)
                  print (dayHighTemps)


                  def daytalkToViz(inputFromXML):
                  global dayCounter
                  dayCounter = dayCounter + 1


                  #---------------------------------------------------------------------------------------------------------------------
                  HOST = '10.55.14.104' # The remote host
                  PORT = 6100 # The same port as used by the server

                  socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

                  socket.connect((HOST, PORT))
                  #--------------------


                  def highTemptalkToViz(inputFromXML):
                  global highTempCounter
                  highTempCounter = highTempCounter + 1

                  #socket.send(b'0 print (highTempCommandPreffix) + str(highTempCounter) + vizCommandPreffix2 + inputFromXML + vizCommandSuffix')
                  socket.send(b'0 MAIN_SCENE*TREE*$high_temp01*FUNCTION*ControlText*input SET 43345' )


                  socket.close()

                  main()

                  Comment

                  Working...
                  X