pdms二次开发入门 c#语言

本文介绍了PDMS的二次开发步骤,包括理解二次开发、获取C#开发资料、创建简单样例程序。详细讲解了如何添加DesignAddins.xml配置、创建类库程序、继承接口并实现功能,最终实现一个显示消息框的命令。适合PDMS新手学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步 了解pdms的二次开发,此处推荐别人的一篇博客。不再重复。
参考链接:博客地址

第二步 c#开发资料的获取。安装pdms后,在安装位置的\Documentation\NetInterfaceReferenceFiles.zip,里面有多个pdms的接口文档说明。
根据名称基本可以判断该接口文件的用处,文件里面也有简介。
基础文件应该先看 Aveva.ApplicationFramework.chm 里面的接口,这是创建UI的入口。
在这里插入图片描述
第三步 开发一个简单的样例程序步骤以及代码。
1.在pdms安装目录,找到 DesignAddins.xml 文件。仿照上面的样式,添加一个HelloWorld。完成。
在这里插入图片描述

注:这个名称是一个索引,会通过这个名称,找到当前安装目录下面的dll文件。如上面的为:HelloWorld.dll
2.a.使用visual sudion 创建一个类库程序,选择.net framework 3.5版本(其他版本可能不支持),创建。在属性里面,最好设置生成路径为pdms安装目录。确认自己的pdms软件版本是64位还是32位,属性-目标平台里面选择对应的x86或者x64。
在这里插入图片描述

b.再创建两个类。一个是UI类,命令为HelloWorldAddin,一个是命令类HelloWorldCommand。此处命名可自定义,无其他关联关系。
c.添加两个引用,在pdms安装目录下找到Aveva.ApplicationFramework.dll和Aveva.ApplicationFramework.Presentation.dll。
3.准备工作完成,开始代码工作。
HelloWorldAddin需要继承Aveva.ApplicationFramework.IAddin接口,实现属性和方法。
HelloWorldCommand需要继承Aveva.ApplicationFramework.Presentation.Command类。实现构造函数和Excute函数

using Aveva.ApplicationFramework;
using Aveva.ApplicationFramework.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorld
{
    public class HelloWorldAddin : IAddin
    {
        public string Name
        {
            get
            {
                return "HelloWorldAddinName";
            }
        }

        public string Description
        {
            get
            {
                return "HelloWorldAddinDescription";
            }
        }
        /// <summary>
        /// 程序打开时,会调用这个方法
        /// </summary>
        /// <param name="serviceManager"></param>
        public void Start(ServiceManager serviceManager)
        {
            //命令管理器上添加一个新的命令
            CommandManager sCommandManager = (CommandManager)serviceManager.GetService(typeof(CommandManager));
            HelloWorldCommand helloWorldCommand = new HelloWorldCommand();
            sCommandManager.Commands.Add(helloWorldCommand);
            //命令栏管理器
            CommandBarManager sCommandBarManager = (CommandBarManager)serviceManager.GetService(typeof(CommandBarManager));
            //在命令栏集合中添加一个新的命令栏
            CommandBar myToolBar = sCommandBarManager.CommandBars.AddCommandBar("helloWorldBar");
            //在工具库集合中添加一个新的按钮工具
            ButtonTool buttonTool = sCommandBarManager.RootTools.AddButtonTool("helloWorldKey", "this a Button", null, helloWorldCommand);
            //在新添加的命令栏上添加这个按钮工具
            myToolBar.Tools.AddTool("helloWorldKey");

        }
        /// <summary>
        /// 程序关闭时,会调用这个方法
        /// </summary>
        public void Stop()
        {
            
        }
    }
}
using Aveva.ApplicationFramework.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelloWorld
{
    class HelloWorldCommand:Command
    {
        public HelloWorldCommand()
        {
            Key = "Hello";
        }
        /// <summary>
        /// 执行的方法体
        /// </summary>
        public override void Execute()
        {
            MessageBox.Show("Hello pdms world");
        }
    }
}

4.生成HelloWorld.dll,确认HelloWorld.dll文件在pdms安装目录下。打开软件Design,点击按钮,最终效果。

在这里插入图片描述
pdms二次开发 新手学习中,文章有问题欢迎指正。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值