It is a little difficult to get the name of the current function, a way that I have found is to make use of the
RefreshPotentialAttributeValues function and then read the
AttributeAValue or
AttributeBValue properties. These are what are used in the numeric entry menu to show softkey options to set attributes on the wheels to, as this is the case they rely on the attributes being on the current bank/group and page (normally this is separate for WebAPI to the UI).
The following code selects the correct bank based on the
controlId number and then looks on each page until it finds the required attribute. The way
RefreshPotentialAttributeValues is processed varies depending on whether the current function is fixed or has a range, in the case of the former you need to pass in a level one less than the current function ID for it to return the name of that function. I don't know how reliable this code will be but perhaps this gives you a starting point to work from.
Code: Select all
async function getAttribute(attributeName) {
// Get the control we are interested in and change bank/group to the one that contains it
let controlId = await runScript('Programmer/Editor/Fixtures/GetControlIdFromName?controlName=' + attributeName);
runScript('Programmer/Editor/Fixtures/SelectAttributeGroupByControl?controlId=' + controlId + '&wheelPageStride=&wheelAllocation=');
let wheel = -1;
for (let i = 0; i < 10; i++) {
// Check if the attribute we are looking for is on the current page
runScript('Programmer/Editor/Fixtures/SetContextAttributeFromId?attributeId=' + controlId);
wheel = await get('Programmer/Editor/Fixtures/CurrentWheel');
if (wheel >= 0) break;
// Try the next page of attributes
let bank = await get('Programmer/Editor/Fixtures/SelectedAttributeBank');
runScript('Programmer/Editor/Fixtures/SetContextAttributeFromId?attributeId=0');
runScript('Programmer/Editor/Fixtures/SelectAttributeBankWithGroup?bank=' + bank + '&wheelPageStride=&wheelAllocation=');
}
if (wheel >= 0) {
// If the current function type is Fixed we need to set the input level to one less than the function ID to get the current function
let functionType = await get('Programmer/Editor/Fixtures/ContextAttribute/FunctionType');
let level = 0;
if (functionType == 1) level = await get('Programmer/Editor/Fixtures/ContextAttribute/FunctionId') - 1;
// Get values for attributes on the current page
runScript('Programmer/Editor/Fixtures/RefreshPotentialAttributeValues?level=' + level + '&wheelPageStride=');
let chr = String.fromCharCode(65 + wheel); // Wheels are labelled A, B, C...
let id = await get('Programmer/Editor/Fixtures/Attribute' + chr + 'Id');
let name = await get('Programmer/Editor/Fixtures/Attribute' + chr + 'Name');
let functionName = await get('Programmer/Editor/Fixtures/Attribute' + chr + 'Value');
let value = '';
if (functionType != 1) value = await get('Programmer/Editor/Fixtures/ContextAttribute/Value');
functionName = functionName.split(/\r\n|\r|\n/g)[0]; // First line is the function name
document.getElementById('output').value += id + ': ' + name + '\n' + functionName + ' ' + value + '\n';
runScript('Programmer/Editor/Fixtures/SetContextAttributeFromId?attributeId=0');
} else {
document.getElementById('output').value += controlId + ' not found!\n';
}
}