首页 > 其他分享 >Eplan-行为

Eplan-行为

时间:2023-07-07 09:46:40浏览次数:25  
标签:调用 行为 public bool new ActionCallingContext ref Eplan

Eplan-行为

初始化

想要在Eplan中实现行为的方法,则需要实现 IEplAction 接口,重写Execute()和 OnRegister()方法。

Execute()方法中为执行的逻辑,

OnRegister()中为行为在方法中注册的名称,若不注册,则为类的名称。

  public class ActionParamAction : IEplAction
    {
        public bool Execute(ActionCallingContext oActionCallingContext)
        { 
            return true;
        }

        public void GetActionProperties(ref ActionProperties actionProperties)
        {
           
        }

        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            return true;
        }
    }

实现场景

行为在Eplan中一共有三种调用方式

  1. 菜单项调用
  2. 行为调用行为
  3. 远程调用行为

菜单项调用

在菜单中绑定行为的名称可以点击触发行为

   public void InitMenu()
        {
            Menu menu = new Menu();
            uint menuNum = menu.AddMainMenu("附加菜单栏", Menu.MainMenuName.eMainMenuHelp, "BoxDevice", "BoxDeviceAction", "", 1);
            menu.AddMenuItem("调用行为", "ActionParaAction", "", menuNum, 1, true, false);
           menu.AddMenuItem("action调用action", "ExecuteAction", "", menuNum, 1, true, false);
        }
public class ActionParamAction : IEplAction
    {
        public bool Execute(ActionCallingContext oActionCallingContext)
        {
            return true;
        }

        public void GetActionProperties(ref ActionProperties actionProperties)
        {
           
        }

        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            Name = "ActionParaAction";
            Ordinal = 20;
            return true;
        }
    }

行为调用行为

行为调用行为的方式,需要actionmanger通过名称找到行为,然后调用

  internal class ExecuteAction : IEplAction
    {
        public bool Execute(ActionCallingContext oActionCallingContext)
        {
            // 查找
            ActionManager manager = new ActionManager();
            Eplan.EplApi.ApplicationFramework.Action action = manager.FindAction("ActionParaAction");
            // 赋值
            ActionCallingContext ctx = new ActionCallingContext();   
            // 执行
            action.Execute(ctx);
            return true;
        }

        public void GetActionProperties(ref ActionProperties actionProperties)
        {

        }

        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            Name = "ExecuteAction";
            Ordinal = 20;
            return true;
        }
    }

在此过程中需要注意,action还有传参和出参,相当于方法中的传参和返回值,这些都要借助于ActionCallingContext这个类来实现

  public class ActionParaAction : IEplAction
    {
        public bool Execute(ActionCallingContext oActionCallingContext)
        {
       		string value1 = "";
            string value2 = "";
// 接收传入的参数
            oActionCallingContext.GetParameter("Param1", ref value1);
            oActionCallingContext.GetParameter("Param2", ref value2);
// 返回string类型的值 其实方式还可以序列化转化obj为string 然后在另一端解析
            string value3 = (int.Parse(value1) + int.Parse(value2)).ToString();
            oActionCallingContext.AddParameter("ReturnParam", value3);

// 通过ContextParameterBlock 返回object 或者 list<obj>类型的值
            ContextParameterBlock block = new ContextParameterBlock();
   
            Book BookVlaue = new Book() { Name = "百年孤独", Price = "12" };
            block.Set("bookPara", BookVlaue);
           

            List<object> stringList = new List<object>() { "aa", "bb", "cc" };
            block.SetList(stringList);

            oActionCallingContext.SetContextParameter(block);
        }
       
    } 

 internal class ExecuteAction : IEplAction
    {
        public bool Execute(ActionCallingContext oActionCallingContext)
        {
            
            ActionManager manager = new ActionManager();
            Eplan.EplApi.ApplicationFramework.Action action = manager.FindAction("ActionParaAction");
            ActionCallingContext ctx = new ActionCallingContext();
            ctx.AddParameter("Param1", "1");
            ctx.AddParameter("Param2", "2");
            action.Execute(ctx);

            // 接收返回值
            string value3 = "";
            ctx.GetParameter("ReturnParam", ref value3);

            object obj = new object();
            ContextParameterBlock contextBlock = ctx.GetContextParameter();
            contextBlock.Get("objParam", ref obj);
            
            List<object> objList =  contextBlock.GetList();

            return true;
        }
    }

远程调用行为

远程调用需要注意eplan占用的地址和端口

 private void Button_Click(object sender, RoutedEventArgs e)
        {
        EplanRemoteClient m_pClient = new EplanRemoteClient();
     // 建立连接
         m_pClient.Connect("127.0.0.1", "49152");   //default port for EPLAN instance is 49155
// 调用
        bool oResp = m_pClient.ExecuteAction("ActionParaAction");
// 断开连接
        m_pClient.Disconnect();
    }

标签:调用,行为,public,bool,new,ActionCallingContext,ref,Eplan
From: https://www.cnblogs.com/alideluobo/p/17533939.html

相关文章

  • 组合电路的行为级建模
    主要使用关键词initial或always定义的两种结构类型的描述语句,initial主要用于面向仿真的过程语句,不能用来描述硬件逻辑电路的功能。1.always结构型说明语句用法:always@(事件控制表达式) begin:块名 块内局部变量的定义; 一条或者多条过程赋值语句; end不停的循环执行其......
  • Unity 在AssetPostprocessor内使用AssetDataBase是不安全的行为(尤其在Build前进行Lib
    https://docs.unity3d.com/Manual/AssetDatabaseCustomizingWorkflow.html在Build前进行Library的删除,读取Asset是不安全的行为,需要使用C#的IOSystem进行操作AssetImportOrderIfyouarescriptingusingtheAssetDatabaseclass,it’simportanttounderstandhowtheor......
  • Eplan-菜单项
    Eplan-菜单项##菜单项使用Eplan菜单的使用主要是添加菜单,和添加二级菜单,涉及到3个添加的方法AddMainMenu()AddMenuItem()AddPopupMenuItem()初始化和创建publicclassEplanMenu:IEplAddIn{publicboolOnExit(){returntrue;......
  • Eplan API -初始化
    EplanAPI-初始化Eplan支持的开发方式一共有3种脚本dll文件形式exe离线程式形式虽然eplan二次开发也支持vb语言,但这里只讨论c#脚本(script)Eplan脚本支持的功能有限,有限的原因在于其支持的程序集有限c#中的System;System.XML;System.Drawing;System.Windows.FormsEp......
  • AI生成文本检测器接口,AI检测,写作质量评估,伪造文件检测,学术不端行为检测,内容审核
     一、接口介绍【可检测出超过98%的AI生成作品】根据输入的内容(中文/英文)即可检测出是人类创作还是AI创作的概率,广泛应用于互联网平台内容审核、写作质量评估、学术不端行为检测和伪造文件检测等场景,以此帮助人们更好地理解和保护自己的知识产权和数据安全。功能体验特别提示:......
  • Java 事务管理@Transactional注解rollbackFor回滚属性,事务的传播行为propagation(REQUI
    事务管理Java事务管理@Transactional注解rollbackFor属性所有的异常都回滚;事务的传播行为propagation(REQUIRED,REQUIRES_NEW)01.事务是一组操作的集合,它是一个不可分割的工作单位。事务会把所有的操作作为一个整体,一起向数据库提交或者是撤销操作请求。所以这组操作要么同时......
  • 第十章 app端用户行为处理
    第十章app端用户行为处理目标能够理解app端的行为记录能够完成作者关注行为的功能能够完成文章点赞行为的功能能够完成文章阅读行为的功能能够掌握不喜欢和收藏功能的实现思路能够完成app文章关系展示功能1app-用户操作行为记录用户行为数据的记录包括了关注、点赞、......
  • elementUI中upload自定义上传行为 http-request属性
    需求是上传一个xlsx后台处理完再返回xlsx流upload请求需要添加responseType:'blob'属性所有要扩展一下若依项目扩展elementUI中upload自定义上传行为http-request属性<el-uploadref="upload1":limit="1"accept=".xlsx,.xls":headers="......
  • 行为模式
    责任链模式责任链模式是一种行为设计模式,允许你将请求沿着处理者链进行发送。收到请求后,每个处理者均可对请求进行处理,或将其传递给链上的下个处理者。比如kratos,gin等开源库的中间件实现。代码实现packagemainimport( "context" "fmt")typeHandlerfunc(ctxc......
  • Windows Group Policy(Windows 组策略)是微软 Windows 操作系统中的一项功能,用于集中管
    WindowsGroupPolicy(Windows组策略)是微软Windows操作系统中的一项功能,用于集中管理和配置计算机和用户的行为和设置。它允许管理员通过创建和应用组策略对象(GroupPolicyObjects,GPOs)来定义操作系统和安全设置,并将这些设置应用于特定的用户或计算机。以下是关于WindowsGroup......