This is the documentation for the new VRED Python API v2 based on Qt for Python (formerly known as PySide 2). View VRED Python API v1 documentation here.
Some functions of the new interface use Qt types for parameters or as return type. Those types are imported automatically into the python namespace and can be used without the need to import them from the PySide2 module.
Additional Qt classes can be imported like this:
from PySide2.QtCore import QLine
from PySide2.QtGui import QBrush
line = QLine(0,0,100,100)
brush = QBrush()
Scene objects in the new interface are derived from vrdObject. Class names for these objects start with vrd (e.g. vrdNode for node objects).
While the objects have many functions to query and change properties, the main entry point is through the services to get the objects you want to work with.
Use services to find existing scene objects, create new objects, delete objects, or access other functions that are available in the related VRED modules.
Annotation: vrAnnotationService
Camera Editor: vrCameraService
Light Editor: vrLightService
Reference Editor: vrReferenceService
Sceneplate Editor: vrSceneplateService
Collaboration: vrSessionService
Virtual Reality: vrDeviceService, vrImmersiveInteractionService, vrImmersiveUiService, vrHMDService
Constraints: vrConstraintService
Loading and saving files: vrFileIOService
Call service functions through an object that has the same name as the service class. For example:
camNode = vrCameraService.createCamera("new camera")
Since VRED moved to Python 3 you can easily install 3rd party modules. You can find a complete Python installation in the installation folder under lib/python. You can use pip to install from the official Python repository. If you want to install ‘numpy’ you can do it like this:
python.exe -m pip install numpy
Pip is developed independent from Python. If you want to upgrade pip to a newer version, use this:
python.exe -m pip install --upgrade pip
If the included pip should stop working you can use Pythons boostrap mechanism to restore it:
python.exe -m ensurepip
You can also manually install modules to Lib/site-packages. If you want to compile your own C or C++ extensions using the Python API be sure to use a compatible compiler. We are using the official Python 3 binaries for VRED without recompiling. So anything, that compiles against the Python distribution from python.org with the same version number as the one shipping with VRED, should work.
This interface can be used via python or via the web interface. The access is done via JavaScript. Function calls are executed asynchronously. The following example shows how such a call could look like from a web page. All parameter and return types are mapped to JavaScript types. QVector3D and QMatrix4x4 for example will be mapped to arrays of 3 or 16 numbers.
<script type="module">
import {api} from '/api.js';
// reacting on a signal
api.vrClusterService.started.connect(() => {console.log('Started')});
// calling a function
api.vrClusterService.start();
// changing the position of the camera
api.vrNodeService.findNode("Perspective")
.then((node) => node.setTranslation([10,20,30]));
</script>>
You might use functions from both API v1 and API v2 in the same script.
In API v1 the node object type is vrNodePtr. You can use vrdNode objects in functions from API v1 that take vrNodePtr as parameter, and vice versa, use vrNodePtr objects in functions from API v2 that take vrdNode as parameter. They’re converted automatically.
To explicitly convert a vrdNode to a vrNodePtr object:
oldNodePtr = toNode(newVRDObject.getObjectId())
You can also convert a vrNodePtr to vrdNode:
newVRDObject = vrNodeService.getNodeFromId(oldNodePtr.getID())
See Scenegraphs in VRED for an introduction on how we refer to scenegraphs in this documentation.
This is a collection of example scripts demonstrating various features of the VRED Python API.
Index
Search Page
This is a list of the VRED Python API v2 commands.