The Nexus API is supplied as a Python package called viconnexusapi and is automatically installed with Nexus. The build of Python installed within Nexus is Python 2. You can run the Python SDK for Nexus in a Python 3 environment as well as in a Python 2 environment.
For more information, see:
Configure Python for scripting with Nexus
To set up Python to work with Nexus:
- Click Start, point to All Programs and then start to type Python.
Click the Python symbol.
To automatically configure Python for scripting with Nexus, at the command prompt, enter the following:
from viconnexusapi import ViconNexus vicon = ViconNexus.ViconNexus()
import viconnexusapi vicon = viconnexusapi.ViconNexus.ViconNexus()
The Python installed with Nexus contains the API version shipped with that version. However, if you install the package into another Python distribution, you are responsible for installing the appropriate version.
For information on how to access the help provided on the relevant Python commands, see Python commands for use with Nexus. For more information about how to use Python, see https://www.python.org/about/gettingstarted/.
If you disconnect your Ethernet cable and turn off wifi, when you enter a Python command, the following error may be displayed:
Host Application is not connected, unable to retrieve command list
This is because Python connects to Nexus over TCP/IP and if you are working entirely offline, Python and Nexus cannot connect.
To solve this issue, install the Microsoft Loopback Adapter. For instructions on how to do this, see Install the Microsoft loopback adapter.
Install the Nexus API into other Python distributions
The build of Python (Python 2) installed within Nexus automatically installs the viconnexusapi package as part of Nexus. A script is also available with both the 32- and 64-bit installers, which installs the package into the system Python distribution. You can also directly install the package into any other Python distributions that you have installed.
cd "C:\Program Files (x86)\Vicon\Nexus2.12\SDK\Win32\Python" # install the api into the system python ./install_vicon_nexus_api.bat # install the api into a specific python distribution <path to user python> -m pip install ./viconnexusapi
The advanced modeling scripts are provided as a package called viconnexusutils and are available in the same way as viconnexusapi, except that these scripts are not automatically installed. This is because they have additional dependencies that cannot be guaranteed to be present and must be downloaded by pip.
Launch the required Python
The shell launched by the python operation is either the Python distribution shipped with Nexus or your default Python (as determined by the PATH variable).
If the Python distribution shipped with Nexus is launched, the API package is automatically available for import, and additional scripts (eg, ViconSetPython32Path.py) are no longer required.
If you choose to use a Python that is different from the installed Nexus distribution, you can use a new advanced option to select the command used to launch Python. The options for this are python.exe or py.exe:
- If you have only a Python 2 or a Python 3 installation in the path, python.exe launches that version of Python.
- If you have both versions and the pylauncher utility, py.exe launches either Python 2 or Python 3, depending on a shebang comment at the start of the launched script.
CGM2 Python version
CGM2 launches using the version of Python 2 installed with Nexus.
Install the Microsoft loopback adapter
To install the Microsoft loopback adapter on Windows 10:
- Right-click the Windows Start menu icon and select Device Manager (or use your preferred method of opening the Device Manager).
- In the Device Manager, click the Action menu and then select Add legacy hardware.
- On the welcome screen, click Next.
- In the Add Hardware screen, select Install the hardware that I manually select from a list and then click Next.
- In the next screen, scroll down the Common hardware types list, select Network adapters and then click Next.
- From the Manufacturer list, select Microsoft, and then select Microsoft KM-TEST Loopback Adapter card model and click Next.
- In the next screen, click Next.
- Click Finish.