如何在Eplan里面添加插件------初级

运行Microsoft Visual Studio并新建一个C#类库项目,如下图所示

http://s4/middle/9a1ad43agc08e09b3c0f3&690API开发之入门篇" TITLE="EPLAN API开发之入门篇" />


新建项目窗口上部选择.NET版本,并设置好项目名称和路径。

重命名C#源文件名为“AddInModule.cs”,类名改名为“AddInModule”。

http://s8/bmiddle/9a1ad43agc08e0b035c17&690API开发之入门篇" />   http://s12/bmiddle/9a1ad43agc08e0ba11adb&690API开发之入门篇" />

 

在项目中添加引用“EPLAN API ApplicationFramework”、“EPLAN API Base”和“EPLAN API Gui”。

http://s8/bmiddle/9a1ad43agc08e0c3f6227&690API开发之入门篇" />

 

 

修改项目属性里的程序集名为“EPLAN.EplAddin.MyAddIn”。

在类“AddInModule”中添加如下内容:

public class AddInModule : Eplan.EplApi.ApplicationFramework.IEplAddIn

   {

       public bool OnRegister(ref System.Boolean bLoadOnStart)

       {

           bLoadOnStart = true;

           return true;

       }

       public bool OnUnregister()

       {

           return true;

       }

       public bool OnInit()

       {

           return true;

       }

       public bool OnInitGui()

       {

           return true;

       }

       public bool OnExit()

       {

           return true;

       }

   }

 

在项目中添加类“MyAction.cs”

http://s2/bmiddle/9a1ad43agc08e0cf85f61&690API开发之入门篇" />

 

打开类“MyAction.cs”,在类中添加如下代码

class MyAction: IEplAction

   {

       public bool Execute(ActionCallingContext ctx )

     {

         System.Windows.Forms.MessageBox.Show("This is a test");

           return true;

     }

     public bool OnRegister(ref string Name, ref int Ordinal)

     {

           Name  = "MyAction";

           Ordinal    = 20;

           return true;

     }

     public  void GetActionProperties(ref ActionProperties actionProperties)

     {

          actionProperties.Description= "Action test with parameters.";

     }

   }

接下来在EPLAN菜单中添加自己的菜单项,在类“AddInModule”的函数“OnInitGui()”中添加如下代码

public bool OnInitGui()

{

     Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();

     oMenu.AddMenuItem("MyAction", "MyAction");

     return true;

}

到此,一个简单的EPLAN API接口就完成了,我们编译生成“EPLAN.EplAddin.MyAddIn.DLL”。运行EPLAN,并加载“EPLAN.EplAddin.MyAddIn.DLL”,大家观察一下工具菜单下多了一个“MyAction”菜单项,点击这个菜单项,会弹出一个“This is a test”的对话框,其实这就是类“MyAction.cs”中的函数“Execute()”的运行结果。

如果你需要点击菜单显示一个自己设计的窗口,只需要自己建立一个窗体类,然后在函数“Execute()”中建个对象就能实现,下面我们来试试看。

在项目中添加“windows 窗体”,并在窗体中插入一个label和一个button,如图所示

http://s15/bmiddle/9a1ad43agc08e0db6eaae&690API开发之入门篇" />

修改函数“Execute()”如下

public bool Execute(ActionCallingContext ctx )

     {

           Form1 MyForm = new Form1();

           MyForm.ShowDialog();

           return true;

     }

     然后重新运行EPLAN,再次点击自建的菜单项“MyAction”,大家会发现刚才设计的窗体出现了。

http://s2/bmiddle/9a1ad43agc08e0e6ec6a1&690API开发之入门篇" />

posted @   爱学习VS  阅读(131)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示