Synchronization during a collaboration session

Here you can see how to send Python commands and how objects can be synchronized automatically. A sphere is created and animated. Half of the animation is synchronized, the other half is not.

vr/collabSyncExample.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3testNode = None
 4loopCount = 1
 5
 6def startTest():
 7    cmd = "node = createSphere(2,300,1,1,0);node.setName('test')"
 8    #send create command to all other users. This is always done asynchronously
 9    vrSessionService.sendPython(cmd,'testNodeState')
10    
11def stopTest():
12    global testNode
13    # create delete command and convert testNode to python string
14    cmd = "deleteNode({})".format(vrSessionService.toPythonString(testNode))
15    #send deletec command to all other users
16    vrSessionService.sendPython(cmd,'testNodeState')
17
18def testLoop():
19    global timer, loopCount, testNode
20    if loopCount == 1:
21        # wait for the node to be created
22        testNode = findNode('test')
23        if not testNode.isValid():
24            return
25        # start synchronize the transformation
26        vrSessionService.addNodeSync(testNode)
27        vrSessionService.sendPython("print('sphere is moving')")
28    if loopCount == 50:
29        # stop synchronize the transformation
30        vrSessionService.removeNodeSync(testNode)
31        print('sphere only moves on this node')
32    if loopCount == 75:
33        # sync the current postion
34        vrSessionService.syncNode(testNode)
35    if loopCount == 100:
36        stopTest()
37        timer.setActive(False)
38    # Animate object
39    setTransformNodeTranslation(testNode, 0, 0, loopCount*10, True)
40    loopCount+=1
41
42timer = vrTimer(0.02)
43timer.connect(testLoop)
44
45def test():
46    global loopCount
47    loopCount = 1
48    startTest()
49    timer.setActive(True)
50
51print("Enter test() to the console to start test")  
52#test()