Simple script with parameters
In This Topic
The script functionality does also accept parameters. However this only makes sense if a parameter can be passed to the script, when it is started. This can be done by invoking EPLAN via the command line:
W3u.exe ExecuteScript /ScriptFile:"C:\Program Files\EPLAN\EPLAN\Basic\Scripts\EPLAN\SimpleScriptWithParameters.cs" /Param1:Hello /Param2:EPLAN /Param3:" API developer!"
When starting EPLAN via command line, in order to run a script, the first parameter is the name of the action to execute. "ExecuteScript" is the action for running scripts. This action takes the parameter "ScriptFile" which specifies the name of the script file to run. Any further parameter (Param1, Param2, Param3) will be passed to the start function of the script.
In the following example, the script (the script function) requires 3 string parameters Param1, Param2 and Param3:
public class SimpleScriptWithParameters
{
[Start]
public bool FunctionWithParameters(String Param1, String Param2, String Param3)
{
new Decider().Decide(EnumDecisionType.eOkDecision, Param1 + Param2 + Param3 , "SimpleScriptWithParams", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
return true;
}
}
Public Class SimpleScriptWithParameters
<Start> _
Public Function FunctionWithParameters(ByVal Param1 As String, ByVal Param2 As String, _
ByVal Param3 As String) as Boolean
Dim dec As Decider = New Decider
dec.Decide(EnumDecisionType.eOkDecision, Param1 + Param2 + Param3, "SimpleScriptWithParams", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK)
Return True
End Sub 'FunctionWithParameters
End Class 'SimpleScriptWithParameters
It is important, that the identifiers (Param1, Param2, Param3) are exactly matching in the command line and in the function!
It is possible to use script with ActionCallingContext as a parameter. To do that please look at the following example:
public class ScriptWithActionCallingContext
{
[Start]
public void FunctionWithActionCallingContext(ActionCallingContext oActionCallingContext)
{
string strFirstParam = "";
string strSecondParam = "";
oActionCallingContext.GetParameter("strFirstParam", ref strFirstParam);
oActionCallingContext.GetParameter("strSecondParam", ref strSecondParam);
string strNewParam = "";
oActionCallingContext.AddParameter("strNewParam", strFirstParam + strSecondParam);
oActionCallingContext.GetParameter("strNewParam", ref strNewParam);
if (strNewParam.Equals(strFirstParam + strSecondParam))
{
// TODO: Add some functionality here
}
}
}
Public Class ScriptWithActionCallingContext
<Start> _
Public Sub FunctionWithActionCallingContext (ByVal oActionCallingContext As ActionCallingContext)
Dim strFirstParam As [String] = ""
Dim strSecondParam As [String] = ""
oActionCallingContext.GetParameter("strFirstParam", strFirstParam)
oActionCallingContext.GetParameter("strSecondParam", strSecondParam)
Dim strNewParam As [String] = ""
oActionCallingContext.AddParameter("strNewParam", strFirstParam + strSecondParam)
oActionCallingContext.GetParameter("strNewParam", strNewParam)
If strNewParam = strFirstParam + strSecondParam Then
' TODO: Add some functionality here
End If
End Sub 'FunctionWithActionCallingContext
End Class 'ScriptWithActionCallingContext
Using this feature, you can extend the scope of the EPLAN command line by your own parameters. If you need to call some API functionality via command line, just create a script. The start function of this script may take parameters and can call other functions with these parameters.