Retargeting and Global Variables

I am building an overview screen that multiple users could have open with “overview” templates in it. Each template will have a script that if clicked, will retarget the user to the master screen. The master screens are running on the shop floor without the overview.

My question is: I want a return button that will only appear if you have retargeted, so I was planning on passing “retargetOcurred” and “hostName” to the project when I retarget as globals. But if two people retarget to the same screen at similar times, will the globals be overwritten or will they be client scoped?

Could I fix this by using a client tag that gets written to when the client launches or how would I best be able to do this?

Global variable aren’t really global – they are per-client. If you look at the documentation for system.util.retarget(), you’ll see that it provides a pair of globals for you that might be all you need. :slight_smile:

Thank you for the quick reply pturmel. :prayer: I could not find the per-client documentation anywhere.

I saw that these pass the two variables, but I wanted to make sure that would impact and other running clients.

My next question on this is I would like build a script that checks if those variables exist, however I cannot seem to get it right. I am using system.util.getGlobals() and it returns what looks like a python dictionary, but when I try to use something like “.has_Key(’_RETARGET_FROM_PROJECT’)”, I get an error saying this is a “stringmap” and does not have an attribute call has_Key. Is there a way I can check if the variable is active without getting an error like this?

Interesting. So it’s really a java Map, not a true python dictionary. So the .containsKey() method would be appropriate. However, jython is generally good at making java Maps look like dictionaries. Have you tried the more pythonish:[code]g = system.util.getGlobals()

do something[/code]Also try listing the contents:[code]for k, v in g:

print k, v[/code]

I think I finally found it:

Looks like if you do

g = dict(system.util.getGlobals())

it will convert it into a callable dictionary.

I was then able to check

if '_RETARGET_FROM_PROJECT' in g: #do something here

I did originally try your suggestion with the “if - in” and I got an error that stringmap was not callable but this looks like it is completing the conversion. Thank you for your help.

Very good.
BTW, the online manual does have some discussion of python scope in the script console and advanced scripting sections.