Is it possible to share values in Collaboration using sendPython?

Is it possible to share values in Collaboration using sendPython?

chaaseLTH9X
Contributor Contributor
83 Views
2 Replies
Message 1 of 3

Is it possible to share values in Collaboration using sendPython?

chaaseLTH9X
Contributor
Contributor

I have a Collaboration session with custom scripts running on both sides.  I would like to be able to send parameter values back and forth between the VRED Pro 2026.1 instances.

 

I tried something like creating a list in one session:

global masterList

 

Then in the other session I created a command which should append an entry to that list:

myCmd = "masterList.append(5)"

vrSessionService.sendPython(myCmd)

 

But I just get this error:

Traceback (most recent call last):

File "<string>", line 1, in <module>

NameError: name 'masterList' is not defined

 

Any ideas to get this to work?  Or is there a better way?

 

-CH

0 Likes
Accepted solutions (1)
84 Views
2 Replies
Replies (2)
Message 2 of 3

chaaseLTH9X
Contributor
Contributor
Accepted solution

I found a work-around, but it is a bit rough:

1) Get a list of connected sessions: myCollabs= vrSessionService.getUsers()

2) Get the host: myHost = myCollabs[0]

3) Use myHost.sendPython(... in combination with mySet = vrVariantSets.createVariantSet(... to create a variant set on ONLY the host.

4) Use myHost.sendPython(... in combination with mySet.addScript(... to add script to the variant set which calls global masterList and then appends the desired entries to the list.  This is tricky to parse the string delimeters using ', \', \\', etc.  But it works!

4) Use vrVariantSets.deleteVariantSet(... to remove the variant set from the host.

 

All of this cleanly adds entries to the masterList on the host session.

 

If anyone thinks of a better way to do this, let me know!

 

-CH

0 Likes
Message 3 of 3

sinje_thiedemann
Autodesk
Autodesk

Hi, the vrSessionService.sendPython executes the Python on both the sending and the connected VRED instances.

 

So that means, if only one VRED instance has an object named masterList, and it does not exist on the other VRED instances, you need to send a command that handles the case that it does not exist:

cmd = """
if 'masterList' in globals():
    masterList.append(5)
    print("added 5 to masterList")
"""
vrSessionService.sendPython(cmd)

 

Or, as an alternative idea, you could also check for the User name and let it only execute by the VRED instance where the user has a certain name:

cmd = """
if vrSessionService.getUser().getUserName() == "host":
    masterList.append(5)
    print("added 5 to masterList")
"""
vrSessionService.sendPython(cmd)