Using Arrays to Create Multiple Watches
Technical Support Guide
Table of Contents
Brand:
- AMX
Models:
- MUSE
Overview:
The below code utilizes arrays to create multiple sets of watch events without having to create a separate watch for each button.
Example Code:
Important!
It is important to remember that creating a watch for something that does not exist in the Descriptor file will cause an exception in the program that will cause the loop to fail and possibly stop the script. Make sure that every step in the array creates a watch for devices, ports, buttons, etc. that exist.
from mojo import context
context.log.info('Sample Python program')
#Gather the context for your devices
dvVaria = context.devices.get("AMX-11241")
#Group ports and buttons numbers that you would create watches for
ports = [1]
transportButtons = [1,3,4]
menuButtons = [5,18,22]
#Function takes in button presses from the transportButtons array of button numbers
def processTransportButtons(event):
print(f"Event info: {event.__dict__}")
#Other event processing goes here
#Function processes button events from the menuButtons array
def processMenuButtons(event):
print(f"Event info: {event.__dict__}")
#Other event processing goes here
#The next two for loops create a watch for each button in the transportButtons and menuButtons arrays
#The watches are created for each panel and each port, in total, each 4 line loop creates 12 watches
for panel in dvTPs:
for portnumber in ports:
for channel in transportButtons:
panel.port[portnumber].button[channel].watch(processTransportButtons)
for panel in dvTPs:
for portnumber in ports:
for channel in menuButtons:
panel.port[portnumber].button[channel].watch(processMenuButtons)
# leave this as the last line in the Python script
context.run(globals())
Table of Contents