Hi all!
I have a question on script variables. In the documentation it is explained that:
"Prior to running a script, operators will first have to link the dummies and parameters to actual elements and values in the DMS. Therefore, it is best to give the variables a meaningful name the operators will be able to work with."
Is there any way that this operator interaction is not necessary? The background is that we would like to execute a script via a task in the scheduler, which has a changing value from a memory file for the parameter.
Best regards and thank you in advance for your inspiring answers!
Daniel
Hi Daniel,
If I understood correctly, you have a memory file defined in the Automation module, and you are using this memory file for your script parameter:
If this is the case, when configuring a scheduled task, the user will need to choose one of the possible values from the memory file:
To avoid this, for example you could remove the script parameter and process the memory file directly in a C# script block. The method GetMemory allows you process the content of a memory file.
Hope it helps.
Hi Daniel,
You might consider designing the script to dynamically retrieve the necessary information (e.g., from a file or memory location) rather than relying on input parameters.
This approach can reduce manual input while still providing the flexibility you need for your use case.
Let me know if this is not possible for your use case. I can try to thing in another solution.
Kind regards,
Hi José, thanks for your answer and the inspiration! I hope I'm on the right track with my script. But now I have the problem that the variable in the view cannot be updated by the script. Please see my addition answer.
Hi José,
Hi Miguel,
thanks for your help, I think to be on the rigth path for a solution.
But now I have the problem to update the variable in my view with the memory file value.
And the second point: I still have to add a memory file dummy(?) on the automation script, to use the "GetMemory" method. Is there any way to call the memory file directly from the C# script? If I don't create a dummy, the memory file is not found.
using System;
using System.IO;
using Skyline.DataMiner.Net;
using Skyline.DataMiner.Net.Exceptions;
using Skyline.DataMiner.Net.AutomationUI;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net.Messages;
public class Script
{
public void Run(Engine engine)
{
engine.Log("Before Memory Load");
ScriptMemory memory = engine.GetMemory("Annotations");
if (memory == null)
{
engine.Log("Memory file 'Annotations' not found.");
return;
}
else
{
engine.Log("Memory file 'Annotations' was loaded successfully.");
}
engine.Log("After Memory Load");
/*
// Speichern von Werten mit aufsteigenden Adressen als Schlüssel
for (int address = 0; address < 1; address++)
{
memory.Set(address, $"Wert an Adresse {address}");
}*/
// Auslesen und Anzeigen der Werte
for (int address = 0; address < 1; address++)
{
try
{
engine.Log("Text vor Get Value on address: ");
object rawValue = memory.Get(address);
if (rawValue == null)
{
engine.Log($"Address {address}: No value found");
}
else
{
string value = rawValue as string;
if (value != null)
{
engine.Log($"Address {address}: {value}");
engine.Log("Text nach Get Value on address: ");
}
else
{
engine.Log($"Adress {address}: Value is not a string (Typ: {rawValue.GetType().Name})");
}
}
}
catch (Exception ex)
{
engine.Log($"Error accessing address {address}: {ex.Message}");
}
}
// Aktualisieren der Visual Overview
UpdateVisualOverview(engine, memory);
}
private void UpdateVisualOverview(Engine engine, ScriptMemory memory)
{
// Annahme: Es gibt einen Parameter in der Visual Overview für jede Adresse
for (int address = 0; address < 1; address++)
{
engine.Log("Befor Visual Overview");
string value = memory.Get(address) as string;
engine.AddScriptOutput(UIVariables.VisualOverview.CreateKey("MyOutput1"), value);
engine.Log("After Visual Overview");
}
}
}
Thank you for the help for a technician who programs 😉
Best regards, Daniel
Hi Miguel, thanks for your answer and the inspiration! I hope I'm on the right track with my script. But now I have the problem that the variable in the view cannot be updated by the script. Please see my additional answer.