Getting object of parent view from embedded view via scripting


So, I have a template view (let’s say view X) in parent project. I am placing this template view in child project’s view (view Y) as an Embedded View Component.

My question is, am I able to get the child’s view object (Y) from template view (X) scripting? So in more general words, am I able to get any component object which is outside Embedded View via scripting?

Best regards,

Suppose you have ViewX and ViewY. ViewX contains an Embedded View, and that Embedded View supplies the path to ViewY, such that you can see ViewY rendered within ViewX.

The only properties you have access to are those which you see in the property editor, so no, you are not able to reference children of ViewY from any scripting in ViewX.

If you need to communicate with children of ViewY from within ViewX, there are three ways to do so. I’ll provide them in order of how much they make sense.

  1. params: if you need to tell ViewY about something - and potentially get information back - params are a fairly easy way to do so. I recommend using in/out params for most scenarios.
  2. Message Handling: While this requires setting up a whole message send/receive paradigm for the components in question, it is far more recyclable and prevents you the need to link bindings to the params.
  3. Bind values to custom session properties. This route works, but requires you to manage a growing list of properties at the session scale. Negligible performance degradation, but I have one project which has hundreds of properties, sometimes nested deep within objects. Whenever I need to reference such a property, I know it’ll be at least a few minutes before I can locate it.

The only properties you have access to are those which you see in the property editor, so no, you are not able to reference children of ViewY from any scripting in ViewX.

I think this explains everything what I wanted. My case is that I would like to set visible property of the Embeded View Component form the scripting in X. My goal was to just place X as an Embeded View and do nothing more (no additional bindings, no additional message handling), all inside X.

Thank you for help.

You’re welcome. you could use a component inside the view which is being embedded to broadcast a message, and then you could have the Embedded View listen for that broadcast and on hearing it set visible to false, or you could use a bidirectional param of the Embedded View to convey whether it should be hidden, and then bind visibility against that param.

I like the message-handling option. But how do I know if View Y is fully loaded before I send a message from View X? In other words, how do we make sure View Y received the message?

You don't. This is the inherent abstraction created by Message Handling: it's great for broadcasting and having multiple pieces hear the same message, but it's like broadcasting a radio signal in that you don't know who's actually listening.

Expanding on the radio signal example, you could turn your system into something akin to a walkie-talkie, where the component which should hear the message "replies" to the original sender.

One example would be a Button which enables some sort of input, and requires a user to submit data before the button may be clicked again. In the button, you could send a message:

# note this script does not disable the button.

Create a Message Handler on the input we will be using (ENABLE_INPUT)

self.props.enabled = True

And then finaly place a Message Handler on the original Button (INPUTS_ARE_ENABLED):

# when this message handler is invoked, it is clear our intended target received the message
self.props.enabled = False

You would need to have additional logic placed to re-enable the Button based on a user submitting their data, but hopefully you see the pattern.