首页 > 其他分享 >Eplan API 初始化

Eplan API 初始化

时间:2023-10-20 14:36:03浏览次数:40  
标签:初始化 return System Eplan API new dll public

Eplan支持的开发方式一共有3种

  1. 脚本
  2. dll文件形式
  3. exe离线程式形式

虽然eplan二次开发也支持vb语言,但这里只讨论c#

脚本(script)

Eplan脚本支持的功能有限,有限的原因在于其支持的程序集有限

c#中的

  • System;
  • System.XML;
  • System.Drawing;
  • System.Windows.Forms

Epaln API中的

  • Namespace Eplan.EplApi.Base
  • Namespace Eplan.EplApi.ApplicationFramework
  • Namespace Eplan.EplApi.Scripting
  • Namespace Eplan.EplApi.Gui
  • NameSpace Eplan.EplApi.Scripting

所以现在基本使用第二种方式来代替,这里只做简单的说明。

脚本分为两种,执行和加载

执行

以Start标注,将写好的.cs文件保存。在【工具-脚本-执行】

 1 using Eplan.EplApi.Base;
 2 using Eplan.EplApi.Scripting;
 3 
 4 namespace EplanDemo.Script
 5 {
 6     class VerySimpleScript
 7     {
 8         [Start]
 9        public void MyFunction()
10         {
11           new Decider().Decide(EnumDecisionType.eOkDecision, "MyFunction was called!", "VerySimpleScript", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
12           return;
13         }
14     }
15 }

加载

或者将其标注为 事件,动作,菜单加载项,在【工具-脚本-加载】

 1   public class SimpleEventHandler
 2     {
 3         [DeclareEventHandler("onMainStart")]
 4         public void MyEventHandlerFunction()
 5         {
 6             new Decider().Decide(EnumDecisionType.eOkDecision, "onMainStart was called!", "SimpleEventHandler", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
 7             return;
 8         }
 9     }
10     public class RegisterScriptMenu
11     {
12         [DeclareAction("MyScriptActionWithMenu")]
13         public void MyFunctionAsAction()
14         {
15             new Decider().Decide(EnumDecisionType.eOkDecision, "MyFunctionAsAction was called!", "RegisterScriptMenu", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
16             return;
17         }
18 
19         [DeclareMenu]
20         public void MenuFunction()
21         {
22             Eplan.EplApi.Gui.Menu oMenu = new Eplan.EplApi.Gui.Menu();
23             oMenu.AddMenuItem("MyMenuText", "MyScriptActionWithMenu");
24         }
25     }
26      public class SimpleScriptAction
27     {
28         [DeclareAction("MyScriptAction")]
29         public void MyFunctionAsAction()
30         {
31             new Decider().Decide(EnumDecisionType.eOkDecision, "MyFunctionAsAction was called!", "RegisterScriptAction", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
32             return;
33         }
34     }

程序集(.dll)

dll文件对编译生成的名称有要求,名称的命名规范为<公司名称>.EplAddin. <NameOfTheProject>.dll.

为了减少不必要的其他bug的出现,推荐使用 .net framework4.7.2,输出的dll文件为64位。

编译完成之后打开epaln软件 选择【工具-API插件-加载-dll所在目录】

ps:dll文件重新编译之后,需要重新卸载之后加载,因为eplan对dll文件的引入采用的是复制dll文件到指定目录,防止在读取dll文件的时候,文件被修改暂用,对于引用的dll文件的其他依赖dll则会在dll的目录中查找。

这里简单做一个加载的菜单项

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using Eplan.EplApi.ApplicationFramework;
 7 using Eplan.EplApi.Gui;
 8 
 9 namespace EplanDemo
10 {
11     public class EplanMenu : IEplAddIn, IEplAddInShadowCopy
12     {
13 
14         private String m_strOriginalAssemblyPath;
15 
16         public void OnBeforeInit(string strOriginalAssemblyPath)
17         {
18             m_strOriginalAssemblyPath = strOriginalAssemblyPath;
19         }
20 
21         public bool OnExit()
22         {
23             return true;
24         }
25 
26         public bool OnInit()
27         {
28             return true;
29         }
30 
31       
32         public bool OnInitGui()
33         {
34             Init1();
35             return true;
36         }
37 
38         public bool OnRegister(ref bool bLoadOnStart)
39         {
40             bLoadOnStart = true;
41             return true;
42         }
43 
44         public bool OnUnregister()
45         {
46             return true;
47         }
48 
49       
50         public void Init1()
51         {
52             Menu menu = new Menu();
53             uint menuNum = menu.AddMainMenu("脚本加载", Menu.MainMenuName.eMainMenuHelp, "功能一", "MyScriptAction", "", 1);
54             menu.AddMenuItem("添加paramater", "AddParameterAction", "", menuNum, 0, false, false);
55             menu.AddMenuItem("显示文字", "ParameterAction", "", menuNum, 0, false, false);
56             menu.AddMenuItem("功能四", "PropertiesACTION", "", menuNum, 0, false, false);
57             menu.AddMenuItem("绘制宏", "DrawingAction", "", menuNum, 0, false, false);
58             menu.AddMenuItem("消息", "MessageAction", "", menuNum, 0, false, false);
59             menu.AddMenuItem("Action", "ActionMangerAction", "", menuNum, 0, false, false);
60         }
61     }
62 }

脱机程式

脱机程式为.exe可执行文件,基本上在windows上分为两种 Winfrom,Wpf

其初始赖于四个dll文件,引入其中。但程序想运行起来还是需要依赖于其他的dll。 在这里有两种处理方式。

  1. 将生成的程式的目录放置在程式的安装目录中 <eplan main path>\Platform\ <version>\Bin folder,
  2. 指定dll文件的形式。
    1. 在程式运行的时候通过反射动态加载未找到的dll文件
    2. 在程式加载的时候引入所有的dll文件

这里只讨论第二种的一二两种方式。

引入dll文件

winfrom在program.cs中,wpf则在app.xaml.cs中引入

动态加载
 1  static class Program
 2     {
 3         /// <summary>
 4         /// 应用程序的主入口点。 winfrom
 5         /// </summary>
 6         [STAThread]
 7         static void Main()
 8         {
 9             
10 
11           //  Application.EnableVisualStyles();
12           //  Application.SetCompatibleTextRenderingDefault(false);
13           //  Environment.CurrentDirectory = @"C:\Program Files\EPLAN2.9\Platform\2.9.4\Bin\"; // x.x.x = your desired EPLAN version
14             AppDomain appDomain = AppDomain.CurrentDomain;
15             appDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
16 
17             Application.Run(new Form1());
18         }
19 
20         static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
21         {
22             Console.WriteLine("Resolving...");
23             string sAssemblyName = args.Name.Split(',')[0];
24             Assembly ass = Assembly.LoadFile(@"C:\Program Files\EPLAN2.9\Platform\2.9.4\Bin\" + sAssemblyName + ".dll");
25             return ass;
26         }
27     }
28 // wpf
29  public partial class App : Application
30     {
31        
32         public App()
33         {
34 
35             Environment.CurrentDirectory = @"C:\Program Files\EPLAN2.9\Platform\2.9.4\Bin\";
36              AppDomain appDomain = AppDomain.CurrentDomain;
37             appDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
38         }
39 
40         static System.Reflection.Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
41         {
42            
43                 Console.WriteLine("Resolving...");
44                 string sAssemblyName = args.Name.Split(',')[0];
45             if (sAssemblyName.StartsWith("Eplan."))
46             {
47                 System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFile(@"C:\Program Files\EPLAN2.9\Platform\2.9.4\Bin\" + sAssemblyName + ".dll");
48                 return ass;
49             }
50             else
51             {
52                // return null ;
53                 return typeof(_Type).Assembly;
54             }
55         }
56     }
引入全部
 1  public partial class App : Application
 2     {
 3         public App()
 4         {
 5            LoadEplanDll();
 6         }
 7   
 8 
 9         static void LoadEplanDll()
10         {
11             string path = @"C:\Program Files\EPLAN2.9\Platform\2.9.4\Bin";
12             DirectoryInfo folder = new DirectoryInfo(path);
13 
14             foreach (FileInfo file in folder.GetFiles("*.dll"))
15             {
16                 Console.WriteLine(file.FullName);
17                 if (file.Name.StartsWith("Eplan."))
18                 {
19                     System.Reflection.Assembly.LoadFile(file.FullName);
20                 }
21             }
22         }
23     }

初始化

 1   private void Window_Loaded(object sender, RoutedEventArgs e)
 2         {
 3          
 4             m_oEplApp = new Eplan.EplApi.System.EplApplication();
 5             String strAppModifier = "";
 6            // System.String strAppModifier = "D:\\200-Document\\210-Work\\212-Code\\HFThridLine\\EplanWpfApp\\EplanWpfApp.exe.config";
 7             m_oEplApp.Init(strAppModifier);
 8 
 9             // Use the finder to find the correct eplan version if not yet known
10             EplanFinder oEplanFinder = new EplanFinder();
11             String strBinPath = oEplanFinder.SelectEplanVersion(true);
12 
13             // Check if user has selected any Eplan variant (Electric P8, etc)
14             if (String.IsNullOrEmpty(strBinPath))
15                 return;
16 
17             //Use the AssemblyResolver to let the program know where all an Eplan variant can be found.
18             AssemblyResolver oResolver = new AssemblyResolver();
19             oResolver.SetEplanBinPath(strBinPath);
20 
21             //Now pin to Eplan. This way all referenced eplan assemblies are loaded from the platform bin path.
22             oResolver.PinToEplan();
23 
24         }

 

标签:初始化,return,System,Eplan,API,new,dll,public
From: https://www.cnblogs.com/ybqjymy/p/17777044.html

相关文章

  • openssl api使用
    实验要求参考https://blog.csdn.net/bruce135lee/article/details/81811403调用OpenSSLAPI0推荐在openEuler中实现,参考https://www.cnblogs.com/rocedu/p/6012545.html第三节1提交相关代码码云(或github)链接2提交不少于6张编译测试过程截图3至少包含SM4,SM3的测试代码......
  • 实验二 OpenSSL API使用
    sm3代码#include<stdio.h>#include<openssl/evp.h>#include<openssl/err.h>#include<openssl/rand.h>voidhandleErrors(void){ERR_print_errors_fp(stderr);abort();}voidtest_sm3(){unsignedchardata[]="Hel......
  • 205-303 K8S API资源对象介绍03 (Job CronJob Endpoint ConfigMap Secret) 2.17-3.3
    一、水平自动扩容和缩容HPA(K8S版本>=1.23.x)HPA全称HorizontalPodAutoscaler,Pod水平自动伸缩,HPA可以基于CPU利用率replicationcontroller、deployment和replicaset中的pod数量进行自动扩缩容。pod自动缩放对象适用于无法缩放的对象,比如DaemonSetHPA由KubernetesAPI资源和控......
  • 解决:Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf
    首次装载IMDB数据集时可能会出现的错误。解决方案:1、先将数据集单独下载下来:datasets/imdb.npz·黄健/keras-datasets-Gitee.com2、将其复制到 ~/.keras/dataset目录下:cpimdb.npz ~/.keras/dataset ......
  • 2023年CANN训练营第二季——叭一叭几款AscendC算子支持芯片的运算单元以及AscendC提供
    前言:    我们知道昇腾AI芯片,有1个或多个AiCore,AiCore上有Cube和Vector运算单元提供给算子进行运算,有的AiCore是Cube和Vector一体的,有的Cube和Vector是分开,各自独立的。我们还记得例程中的例子一般都指定核心数BLOCK_DIM=8,这又是为什么,有啥道理呢?本文就来叭一叭,昇腾芯片的运......
  • 接口管理神器Apipost
    自诞生以来,Apipost凭借其简洁直观的用户界面、强大的功能以及简单、易上手的操作,让Apipost成为了开发人员不可或缺的工具。本文将详细介绍Apipost的主要功能和使用方法,帮助大家更好地了解这款优秀的API开发工具。下载安装直接进入Apipost官网下载即可,也可以直接使用web端无需下载AP......
  • 接口管理神器Apipost
    自诞生以来,Apipost凭借其简洁直观的用户界面、强大的功能以及简单、易上手的操作,让Apipost成为了开发人员不可或缺的工具。本文将详细介绍Apipost的主要功能和使用方法,帮助大家更好地了解这款优秀的API开发工具。下载安装直接进入Apipost官网下载即可,也可以直接使用web端无需下......
  • 容器环境中安装salt-master salt-api
    FROMcentos:7RUNcurl-fsSLhttps://repo.saltproject.io/py3/redhat/7/x86_64/3004.repo|tee/etc/yum.repos.d/salt.repo&&\sed-i"s/repo.saltproject.com/mirrors.aliyun.com\/saltstack/g"/etc/yum.repos.d/salt.repo&&\......
  • “当当平台关键字搜索API:轻松实现高效购物,获取海量商品信息!“
    1688商品评论接口是一种供卖家使用的接口,可以让卖家通过该接口维护商品的评论信息,包括评论内容、评分、评论时间等等。通过使用该接口,卖家可以方便地管理商品的评论信息,包括查看、修改、删除评论等操作。同时,该接口还支持卖家对商品进行评分,以帮助其他买家更好地了解商品的质量和特......
  • 实验二 OpenSSL API使用
    SM3测试代码#include<stdio.h>#include<string.h>#include"openssl/evp.h"#include"err.h"voidtDigest(){unsignedcharmd_value[EVP_MAX_MD_SIZE];intmd_len,i;EVP_MD_CTX*mdctx;charmsg1[......