Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
Bentley 中国优先社区
  • Welcome to Bentley Communities
  • Bentley's Communities
  • Bentley 中国优先社区
  • Cancel
Bentley 中国优先社区
技术资料库 Bentley Substation二次开发入门
    • Sign In
    Bentley 中国优先社区 requires membership for participation - click to join
    • -Bentley 中文技术资料库
      • +AutoPIPE
      • +Bentley Civil
      • +Bentley Navigator
      • -Bentley Substation
        • +00-版本更新
        • +01-常见问题
        • +02-快速入门视频及文档
        • +03-安装、激活、升级、库配置及PW集成
        • +04-图形与用户界面
        • +05-工程与图纸管理
        • +06-模型及符号库管理
        • 07-主接线图设计
        • +08-三维设备及导体布置
        • +08-操作文档
        • +09-防雷设计
        • +10-接地设计
        • +11-二维图及报表模块
        • +12-工程交付与数据检测
        • 13-校验计算
        • -14-二次开发
          • Bentley Substation二次开发入门
          • Substation Plugin创建数据库表支持项目备份与恢复操作
        • +Bentley Substation 中国工具包
        • +Bentley Substation 自述文件
        • +Bentley Substation软件使用
        • Substation 报表中定义序号
      • +BRCM
      • +BridgeMasterModeler/OpenBridgeModeler
      • +i-model / DgnDb
      • +LumenRT/ContextCapture
      • +MicroStation
      • +MOSES
      • +OpenBuildings Designer
      • +OpenFlows
      • +OpenPlant
      • +OpenPlant Electrical CCK
      • Plaxis 地质分析
      • +ProjectWise
      • +ProStructures
      • +SACS
      • +STAAD.Pro
      • +SYNCHRO Pro
      • +其 它
      • +建筑设计之思考(赵大师专作)
      • +桥梁大师<BridgeMaster>
      • +现浇箱梁
      • +软件激活及授权
    • +iTwin 数字孪生平台
    • Bentley二次开发资料库
    • +常见问题汇总
    • Bentley-Learn 官方教学平台-使用方法
    • +中国优先社区使用指南
    • +Bentley学习资料库
    • +Bentley用户成功活动精选
    • +服务合作伙伴计划

     
     Questions about this article, topic, or product? Click here. 

    Bentley Substation二次开发入门

    Bentley Substation插件由以下三部分组成:

    • 一个.net的dll文件,作为插件的入口。这个文件中必须包含一个实现插件接口(ECT.ECAD.API.PlugIn.IPlugInBase)的public的类。

    • Config.xml文件,指定插件入口的dll文件和其中实现插件接口的类的名称。

    • Description.xml文件,包含插件的描述信息和版本信息。

    插件文件放在Bentley Substation安装路径下的plugins目录里的子目录,一个子目录对应一个插件,例如:“C:\Program Files (x86)\Bentley\Substation V8i\Substation\Promise\plugins\PLCGenerator”。

    插件接口说明

    接口定义

    namespace ECT.ECAD.API.PlugIn

    {

       public interface IPlugInBase

       {

           void Init();

           void OnCustomMenuCommand(string strCommand);

           void RegisterCustomMenu(out ArrayList arrMenu, out ArrayList arrMode);

           void Unload();

       }

    }

    函数说明

    • Init是插件初始化函数,当插件被加载的时候被执行。通常会再这里注册插件菜单。

    • OnCustomMenuCommand是点击插件菜单项的事件响应函数。strCommand是点击的菜单项的名称。注意:点击任何一个插件菜单项,都会触发该函数。因此,务必要判断strCommand是否是这个插件注册的菜单项。

    • RegisterCustomMenu是根据Bentley Substation的图纸页模式(Schematic Mode, Panel Layout Mode, etc.)来注册菜单。arrMenu中存放菜单项的名字,arrMode存放菜单项对应的模式的名字,两个ArrayList中的元素是一对一的。目前这个功能不常用,把arrMenu和arrMode设为null就行了。

    • Unload在插件被卸载的时执行,基本没用。

    Bentley Substation插件开发示例

    通常使用C#或VB.net进行开发。以C#为例:

    新建一个Class Library类型的工程

    添加Bentley Substation的引用

    在Bentley Substation安装路径里的如下文件可以被引用:

    1. ECT.ECAD.API.dll,是业务逻辑模块。插件工程必须引用,因为它包含了ECT.ECAD.API.PlugIn.IPlugInBase的定义。

    2. ECT.ECAD.DAL.dll,是数据访问模块。如果需要访问promis-e数据库,则必须引用。

    3. ECT.ECAD.UI.dll,是用户界面模块。

    4. Interop.EctEcad.dll/MicEctEcad.dll, Bentley Substation的图形平台接口的实现。如果需要操作对图形元素,则引用。

    插件中,引用Bentley Substation安装路径中的dll文件时,“Copy Local”属性要设成False。因为插件是被Bentley Substation加载的,所以插件用到的dll文件已经被加载到Bentley Substation的进程中。

    实现ECT.ECAD.API.PlugIn.IPlugInBase的接口

    这里是PlugInDemo.Class1。

    using System;

    using System.Collections.Generic;

    using System.Text;

     

    using ECT.ECAD.API;

     

    namespace PlugInDemo

    {

       public class Class1 : ECT.ECAD.API.PlugIn.IPlugInBase

       {

           #region IPlugInBase Members

     

           public void Init()

           {

               // 注册两个菜单项

               Root.App.DrawingTool.RegisterCustomMenu("DemoMenu1");

               Root.App.DrawingTool.RegisterCustomMenu("DemoMenu2");

               // 完成注册

               Root.App.DrawingTool.CustomMenuApplyChanges();

           }

     

           public void OnCustomMenuCommand(string strCommand)

           {

               if (strCommand == "DemoMenu1")

               {

                   // DemoMenu1被点击

               }

               else if (strCommand == "DemoMenu2")

               {

                   // DemoMenu2被点击

               }

           }

     

           public void RegisterCustomMenu(out System.Collections.ArrayList arrMenu, out System.Collections.ArrayList arrMode)

           {

               arrMenu = null;

               arrMode = null;

           }

     

           public void Unload()

           {

           }

     

           #endregion

       }

    }

    编写Config.xml

    PlugInDemo.dll是文件名,PlugInDemo.Class1是完整的(实现了插件接口的)类名。

    <?xml version="1.0" encoding="utf-8" ?>

    <Config Enable="true" EntranceModule="PlugInDemo.dll" EntranceClass="PlugInDemo.Class1">

    </Config>

    编写Description.xml

    这里可以填写作者(Your Name)、插件名称(PlugInDemo)、版本号(1.0)、发布日期(2009.1.26)等信息。

    <?xml version="1.0" encoding="utf-8" ?>

    <Descriptions Author="Your Name" Name="PlugInDemo" Version="1.0" ReleaseDate="2009.1.26">

    <Desc></Desc>

    </Descriptions>

    布置插件到Bentley Substation

    新建一个文件名叫PlugInDemo(名称可以随便起)的文件夹,将编译的dll文件、Description.xml复制进去,然后把这个PlugInDemo文件夹放到Bentley Substation安装路径下的plugins文件夹里。

    新建同名文件夹PlugInDemo,将Config.xml复制进去,然后把这个PlugInDemo文件夹放在Bentley Substation的ProgramData路径的plugins文件夹中,如C:\ProgramData\Bentley\Substation V8i\Plugins\PLCGenerator。

    启动Bentley Substation后,插件会被自动加载。

    Substation Plugin示例程序下载:SubstationPluginDemo.zip  

    Substation Plugin类库说明:Substation_API.chm

    下载链接:https://pan.baidu.com/s/1iNFeQYja7dhgf8uppMnqLQ   提取码:b5jx

     

    • Bentley Substation
    • Share
    • History
    • More
    • Cancel
    • xuehui.gong Created by Bentley Colleague xuehui.gong
    • When: Thu, Apr 21 2016 1:44 AM
    • Yuhui Liu Last revision by Bentley Colleague Yuhui Liu
    • When: Mon, Sep 23 2019 11:33 PM
    • Revisions: 3
    • Comments: 0
    • Sign in to reply
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies