Get fixture attribute function name

Discussion and chat related to developing interfaces to the Titan software using the web API.

Moderator: Moderators

Jorge Garcia
Posts: 5
Joined: 13 Apr 2024, 14:36

Get fixture attribute function name

Postby Jorge Garcia » 30 Apr 2024, 09:53

Hello

After selecting the fixtures and set the context attribute with:
http://localhost:4430/titan/script/2/Pr ... ibuteId=32

I can get the function Id and the function type:
http://[ip]:4430/titan/get/2/Programmer/Editor/Fixtures/ContextAttribute/FunctionId
http://[ip]:4430/titan/get/2/Programmer/Editor/Fixtures/ContextAttribute/FunctionType


But is possible to get the function name? I mean, when the attributes have enum values, like "open", "close", etc... is possible to get this description?

Thanks for your help...
User avatar
Gregory
Posts: 1306
Joined: 14 Dec 2007, 15:25
Location: London, United Kingdom
Contact:

Re: Get fixture attribute function name

Postby Gregory » 43 minutes ago

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';
  }
}

Who is online

Users browsing this forum: No registered users and 3 guests