system.perspective.sendMessage not triggering Session Events Message Handlers

What a title…
So i am trying to set session properties via a system.perspective.sendMessage call.
My call is defined as follows:

system.perspective.sendMessage(messageType= "SetNavProps_Area", payload=payload, scope ="session", sessionId =

And my message handler is defined here:

Why does this seem to not work, but if i define a message handler on a View root container, then it can pick it up?

Ah so i think this is because the “session” in this scope, is a totally different session to where the sendMessage script is defined.
Is there no way to reference this other session? and set its properties?

system.perspective.sendMessage() is invoked as a broadcast where you specify the scope you want to broadcast to. The Session Event Message handler ONLY hears message from the Gateway which were broadcast with a scope of “s”

# This will broadcast from the Gateway to all sessions, and the session must have a listener configured
# in the Session Events pane.
system.util.sendMessage("ProjectName", "MessageHandlerName", payload={"someValueKey": "SomeActualValue"}, scope="s")

Thank you, i did discover that i could trigger it with system.util.sendMessage() as you described.
I just wasn’t sure exactly why, thank you for clarifying that.

I don’t think this specific handler is going to work for me though, as it doesn’t have any scope of the session where the action was taken. It is gateway scope as you say.

As far as i can tell, there is no way to set custom properties of a session without being in scope of that session.

Session Events have the session passed in as an object. Look at the arguments in the documentation at the top of the Handler.

You could try doing something like this:

# assuming the payload passed into system.util.sendMessage has a key of "someOtherProperty"
session.custom.someProperty = payload["someOtherProperty"]

Edit: Looking closer at your screenshot, it looks like you’re already doing something like this. Could you clarify where you’re getting hung-up?

2nd edit: That navigation call also looks correct. Are you encountering the mentioned stacktrace while using that invocation? I can try to work out what’s happening in the morning, but it looks correct to me.

So the issue i am having with using the system.util.sendMessage() in combination with the Gateway Perspective Session Events Message Handlers, is that it updates custom properties across ALL sessions, which is not desirable.

I’m trying to engineer a project where session properties are used for navigation, such as updating a header banner value, or a footer to tell you where you are in the project.

I’ve tested this again, and notice that on two different sessions, with unique session IDs, when i use this method, the header session property is updated on both sessions, and not the session where the function originated from.


Perspective Workstation session’’

Browser session

Updating using the “set props” button on the browser

Also, this is the output from a logger i have on the Session Events Message Handler:

Not sure why it is being triggered three times… I have 2 designer sessions open, one perspective session and a browser.

This is why i was asking about passing in the session from the button click, so that it can be used to set the properties on the originating session.

Yes, the Session Events are Events for ALL sessions. If you want to limit the sessions who hear the call, then you need to supply a clientSessionId argument to system.util.sendMessage() You should do this instead of passing the session ID.

system.util.sendMessage("ProjectName", "MessageHandlerName", payload={"someValueKey": "SomeActualValue"}, clientSessionId="<target_session_id_here>", scope="s")

But this has me questioning how all of this is held together:

If you’re making these calls from the current session, why don’t you just directly set the session properties instead of trying to set up a complicated and potentially high-maintenance messenger system?


Ah of course… thank you. I think i’ve flipped between the two different message send functions too many times and got mixed up with what parameters could be sent.

Ok yes so now that works as i wanted… thank you.

The whole point of this setup originally (there have been multiple things i’ve been trying to test over the last few days) was to allow myself to set session custom properties from a gateway scoped script, such as the Project script library.
The reason for this, is that i wanted to create custom navigation scripts in those libraries which could handle multiple tasks in one function. Such as for navigation buttons, that take you to different areas/sub areas of the plant:

  1. Set session property of the area you are navigating to
  2. Set session property to update the header to match the page/view you are navigating to
  3. Log the operator action (using pre-built script library function)
  4. Do the actual navigation

A lot of this is stemming from playing around with different ways to do things, and trying to learn what Perspective can do and how we want to approach it.
Haven’t quite settled on a final solution yet, so thank you for bearing with me on this one!

1 Like