/
Connect a Python client to Shogun Live

Connect a Python client to Shogun Live

For information related to connecting a Python client to Live, see the following topics.

Create a client and check the connection

  1. Start Shogun Live. It is now ready to be interacted with via the Python API.

  2. To connect to the terminal server, import the Vicon Core API module.

    import vicon_core_api
    from vicon_core_api import *
  3. Create a client. This automatically tries to connect to the specific host address on the default port (52800). In this example, the object is named shogun_client:

    shogun_client = Client('localhost')

    Where:

    • shogun_client is the name of the object, which can be any name you want
    • localhost can be replaced with an IP address or hostname running Shogun Live.
  4. Check that the client is connected:

    shogun_client.connected

    This returns True if connected, and False if not.

    If the response is False, ensure that you have the following in place before creating a new client:

    • An instance of Shogun is open and running

    • The specified host address is on port 52800

    • Your firewall is not blocking traffic on port 52800.

When you have successfully connected, you can access the services provided by the Shogun Live terminal server, such as CaptureServices, and interact with Shogun Live.

Example: Setting the capture name

In Shogun Live, towards the top of the Capture panel, the default capture name is Take.

You can change the name of the take using the Python API and CaptureServices (which provides most of the functionality available in the GUI).

Note that both CaptureServices and SubjectServices require a connected client on construction.

This example shows you how to retrieve and change the capture name using the Python API.

Get the capture name

  1. Import the relevant class for interacting with capture:

    import shogun_live_api
    from shogun_live_api import CaptureServices
  2. Create an object for the capture services. In this example, the object is named capture, but you can enter any name you like.

    This name references the object used for the shogun client that was created:

    services = CaptureServices(shogun_client)
  3. CaptureServices provides access to most of the functionality available in the GUI. We can use one of the functions in this class to look at the capture name. First, check the name of the capture can be retrieved.

    result, capture_name = services.capture_name()
    print(result)

  4. The result should be a success.

    (warning) Note: All API calls return a result code (which are described in vicon_core_api/result.py files) - run help(vicon_core_api) for more information. One possible failure code is Result.RPCNotConnected, which is received if the connection to the terminal server is lost.

  5. Print the name of the take using:

    print(capture_name)

Change the capture name

  1. Use the set_capture_name method to set the capture name to 'MyTake001':

    result = capture.set_capture_name('MyTake001')
  2. Enter result, to check the return value to make sure that this succeeded. Below is an example of the terminal and result.

  3. Enter print(capture_name) to check the name has been changed.

  4. Go to Shogun Live and check the capture name has changed.

For further information, see:

  • The readme file: C:\Program Files\Vicon\ShogunLive#.#\SDK\Python\readme.txt
  • Sample scripts: C:\Program Files\Vicon\ShogunLive#.#\SDK\Python\sample_scripts

To display a list of all available functions and documentation

help(shogun_live_api)

Explore using Python

Run the Python dir() command on objects created, to show the methods that can be called:

For example, dir(shogun_client) or dir(capture)

Run help() on specific methods or classes.

For example, help(capture.set_capture_name)