在EPLAN中,什么被称为“动作”?
动作是可以在EPLAN中动态注册的过程或功能。动作通过其名称和重载优先级来标识。一个动作可以有任意数量的参数,这些参数通过所谓的ActionCallingContext传递给动作并从动作返回。在EPLAN中,每个功能区按钮都与一个动作关联,当点击功能区按钮时,该动作就会被调用。
一个插件可以向EPLAN添加新的动作。动作可以从命令行调用,也可以被分配给新的功能区按钮。新的动作可以覆盖具有相同名称的现有动作。
动作由一个继承了IEplAction接口的类实现。你需要添加该接口所有函数的实现。一个插件可以包含任意数量的动作。
public class CSharpAction: Eplan.EplApi.ApplicationFramework.IEplAction
{
///<summary>
///This function is called when executing the action.
///</summary>
///<returns>true, if the action performed successfully</returns>
public bool Execute(Eplan.EplApi.ApplicationFramework.ActionCallingContext ctx )
{
new Decider().Decide(EnumDecisionType.eOkDecision, "CSharpAction was called!", "Eplan.EplAddIn.Demo1", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
// TODO: Add your Code here
return true;
}
///<summary>
///This function is called by the application framework, when registering the add-in.
///</summary>
///<param name="Name">The action is registered in EPLAN under this name</param>
///<param name="Ordinal">The action is registered with this overload priority</param>
///<returns>true, if OnRegister succeeds</returns>
public bool OnRegister(ref string Name, ref int Ordinal)
{
Name = "CSharpAction";
Ordinal = 20;
return true;
}
///<summary>
/// Documentation function for the action, which is called by EPLAN on demand
/// returns the descriptive text for the action itself and if the action takes string parameters
/// (command line), it also provides the name and description of each parameter
///</summary>
///<param name="actionProperties"> This object needs to be filled with information about the action
///</param>
public void GetActionProperties(ref Eplan.EplApi.ApplicationFramework.ActionProperties actionProperties)
{
actionProperties.Description= "Action test with parameters.";
// description of first parameter
Eplan.EplApi.ApplicationFramework.ActionParameterProperties firstParam= new ActionParameterProperties();
firstParam.Set("Param1", "first test parameter");
actionProperties.AddParameter(firstParam);
// description of second parameter
// Eplan.EplApi.ApplicationFramework.ActionParameterProperties secondParam= new ActionParameterProperties();
// secondParam.Set("Param2", "Second parameter for test");
// actionProperties.AddParameter(secondParam);
}
}
类型为ActionCallingContext的参数可以用于向动作传递参数。为了提取参数值和设置参数(作为返回参数),ActionCallingContext类提供了一组函数:
public bool Execute(Eplan.EplApi.ApplicationFramework.ActionCallingContext ctx )
{
String strParamValue=null;
ctx.GetParameter("Param1", ref strParamValue);
// use string parameter ...
// fill parameter "ReturnParam" with value "return value".
// the caller of this action can extract the parameter by ctx.getParameter("ReturnParam", ...)
String strReturnValue= "return value";
ctx.AddParameter("ReturnParam", strReturnValue);
return true;
}
当一个动作被分配给功能区按钮时,这些按钮项只有在该动作被注册并启用时才会被激活。你可以通过IEplActionEnable接口启用或禁用已注册的动作。
public class TestAction : Eplan.EplApi.ApplicationFramework.IEplAction, Eplan.EplApi.ApplicationFramework.
{
//IEplAction Members
#region IEplActionEnable Members
public bool Enabled(string strActionName, Eplan.EplApi.ApplicationFramework.ActionCallingContext actionContext)
{
if (strActionName == "TESTACTION")
{
return false;
}
else
{
return true;
}
}
#endregion
}