Below is some code I use in the INITIALIZE method to populate the Keypad with buttons when added to the UI. The code looks up the bound Lutron Keypad device , scans the Lutron buttons and creates the necessary Button objects under the Keypad.
I am also trying to dynamically create a CommandMacro for each button which toggles the Lutron button trigger property when someone presses the button. Everything works fine except I am having problems setting the TargetProperty on the newly created macro object.
The code executes OK, the buttons are created under the Keypad, and macros are created under each button but the TargetProperty of the macros remains empty.
Here is the code:
if this.LutronKeypad is nothing then this.StatusMessage = "Please set the LutronKeypad property before initializing buttons." else 'Lookup all the buttons of the Lutron Keypad and set their names for each oButton in this.LutronKeypad.GetChildren if oButton.Class.Path = "sys://Schema/Lutron/HWI/HWI_Button" then set newButton = this.CreateObject("sys://Schema/Device/Keypads/Button","Button_" & cstr(oButton.ButtonID) ) newButton.DisplayName = oButton.DisplayName ' Create the same display name as the Lutron label newButton.BoundObject = oButton 'Create a reference to the button device 'Create a macro for each button so that it triggers the device button set oNewMacro = newButton.CreateObject("sys://Schema/System/CommandMacro","CommandMacro" ) oNewMacro.TargetObject = oButton oNewMacro.TargetProperty = schema.Device.ButtonTrigger.Trigger oNewMacro.TargetAction = schema.System.Boolean.Toggle set oNewMacro = nothing set newButton =nothing end if next this.StatusMessage = "Buttons Initialized" end if