Im fairly new to text programming and was wondering if there was a function or notation in scripting that works the same way as in indirect tags.
Where in indirect tags I would use {1} to reference another variable.
Im trying to do a simple if statement in a propertyChange script.
example:
if event.propertyName == "DeviceChange"
DynamicDeviceName = "DeviceName" #F1,F2,F3,F4,F5,F6,F7,F8 and so on........
#The DynamicDeviceName has over 40 different possibilities.
if event.source.Service."DynamicDeviceName" == 1: #DynamicDeviceName is defined by which DeviceName is present.
print "Good Vibes only"
if event.source.Service.F1 == 1:
print "SomeCoolStuff"
#F1 is a device but it can also be:
if event.source.Service.F2 == 1:
print "SomethingElse"
#since "F2" is also a Device in the udt
# event.source.Service is a reference to a Template property called Service which is a UDT that contains 42 booleans.
# So to call upon the wanted information I Wish to call upon event.source.Service.F1 when the DeviceName is F1
Can you edit your question (pencil icon), select each piece of code and use the </> code formatting button to format your code? This will preserve indentation, apply syntax highlighting and make it much easier to read.
Unless service is a property on a custom component from a module, I don't think this is valid. Though even if its a custom component from a module, I don't think this is valid python regardless.
The goal is to set a status based on a boolean that declares if the machine is out for service
I created a user defined tag UDT containing the different tags.
I basically want to insert a string containing the DeviceName into my if statement âevent.source.Service.â and from there reach the âpositionâ in the UDT (User defined Tag)and get the False/True from the tag.
is not going to work. Because the type UDTProperty doesnât have an F1(or whatever) method.
Something like this might work though (Not even close to being tested):
if event.source.Service.TagPath.getItemName() == 'F1':
if event.source.Service.getValue(event.source.Service.TagPath).value:
print "Some Cool Stuff"
Honestly though, Iâm not sure youâre approaching this correctly? Is one indicator going to show the status of 42 different booleans? Why wonât an indirect tag binding work?
I would consider using two properties on the template One that holds the base path to the UDT and another that holds the Device name. Then use those to build and indirect tag binding for the status indicator. No script needed.
What propertyChange event is this firing on? I would recommend against putting this on any vision componentâs property change. Seems like this should be a gateway tag change event or in the gateway context of some sort.
It can be done using eval(), but, just because it can be done doesnât mean that it should be done. eval() can be very dangerous to use as it will try to execute anything you put into it. Even bad stuffâŚ
service = event.source.parent.getComponent('LH Container').Service
deviceList = ['F1', 'F2', 'F3']
for device in deviceList:
print eval('service.{}'.format(device))
I would add memory tags to your UDT, write a gateway timer script to poll the tags, and then set the memory tags to whatever status you need.