This code example will log the preset data for a channel selected in the Preset Documentation view.
-- Example code of how to access and use MLA preset data
-- Copyright Andrew Voller Lighting Design Limited, 2019
-- TriggerType=Menu
-- DisplayOutputWindow=true
-- Get a preset object for the currently selected channel in the Preset Doc view.
function GetPresetObjectForSelectedChannel()
channelNumber = 0
presetType = "none"
presetID = 0
-- Get currently selected channel.
channelInfo = PresetInfo:GetSelectedChannel()
if channelInfo ~= nil then
channelNumber = channelInfo.ChannelNumber
presetType = channelInfo.PresetType
presetID = channelInfo.PresetID
end
-- Get Preset data object
presetObject = PresetData:GetPresetObject(channelNumber, presetType, presetID) -- channel, preset type, preset id
return presetObject
end
-- Return the parameter name for a given parameter index. 1 based.
function GetPresetNameByIndex(parameterIndex, presetObject)
parameterName = ""
if parameterIndex >= 1 and parameterIndex <= presetObject.NumParameters then
-- Create a key to access table entry
tableKey = "ParameterName"..tostring(parameterIndex)
parameterName = presetObject[tableKey]
end
return parameterName
end
-- Return value for named parameter
function GetParameterValueByName(parameterName, presetObject)
parameterNumber = 0
parameterValue = ""
for iter=1, presetObject.NumParameters do
iterName = GetPresetNameByIndex(iter, presetObject)
if iterName == parameterName then
parameterNumber = iter
break
end
end
if parameterNumber > 0 then
tableKey = "ParameterValue"..tostring(parameterNumber)
parameterValue = presetObject[tableKey]
end
return parameterValue
end
-- Main
-- Get a preset object for the currently selected channel in the Preset Doc view.
presetObject = GetPresetObjectForSelectedChannel()
if presetObject ~= nil then
io.write("Channel: ", presetObject.Channel, "\n")
io.write("Preset Type: ", presetObject.PresetType, " PresetID: ", presetObject.PresetID, "\n")
io.write("Preset Name: ", presetObject.PresetName, "\n")
io.write("Number of Parameters: ", presetObject.NumParameters, "\n")
-- Example to display data for the first parameter.
--io.write("Parameter 1 Name: ", presetObject.ParameterName1, "\n")
--io.write("Parameter 1 Value: ", presetObject.ParameterValue1, "\n")
--io.write("Parameter 1 Effect: ", presetObject.ParameterEffect1, "\n")
--io.write("Parameter 1 Nested: ", presetObject.ParameterNested1, "\n")
-- Example to list parameter names.
for iter=1, presetObject.NumParameters do
parameterName = GetPresetNameByIndex(iter, presetObject)
parameterValue = GetParameterValueByName(parameterName, presetObject)
io.write("Parameter ", iter, ": ", parameterName, ": ", parameterValue, "\n")
end
-- Example to display Pan & Tilt values.
--panValue = GetParameterValueByName("PAN", presetObject)
--io.write("Pan: ", panValue, "\n")
--tiltValue = GetParameterValueByName("TILT", presetObject)
--io.write("Tilt: ", tiltValue, "\n")
end
Note that there are several comment out --
sections that show different ways of using the data. It is best test this example out in the Moving Light Assistant built in script editor. Ensure that the Open Output Window checkbox is checked.