Referencing view parameters in perspective via scripting

What is the syntax for referencing a views parameters in an event script. I have a view called Motor which has an view parameter called MotorNumber. I’m trying to set a tag by incorporating this in an event script like this:

tp = '[CodeSys]Testing/mtr' + str(self.parent.parent.MotorNumber) + 'StopPB'
system.tag.write(tp,1)

This doesn’t cause any errors. If I hard code the path, it works.

While you are able to use system.tag.write() in perspective, you should use system.tag.writeAsync() as system.tag.write() is essentially deprecated (in your script type out “system.tag.” then hold Ctrl and tap Space to see available methods).

Assuming self.parent.parent indeed refers to the View, then you should try one of two ways (which should both do the same thing):

  1. str(self.parent.parent.params.MotorNumber)

or

  1. str(self.view.params.MotorNumber)

Option 2 will remove the potential issue which could pop up if you ever move the component into a container at a different level.

Further documentation.

2 Likes