计量论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[工程参量] C#二次开发连接pc-dmis代码

[复制链接]
huangwang 发表于 2024-10-9 11:50:21 | 显示全部楼层 |阅读模式
using PCDLRN;
namespace PCDMIS
{
    internal static class ConnectPcDMIS
    {
        public static Application? Application;
        public static PartProgram? PartProgram;
        public static Commands? Commands;
        public static bool PCdmisState;

        public static Commands? GetCommands()
        {
            Type? comType = null;
            object? comObj = null;
            try
            {

                comType = Type.GetTypeFromProgID("PCDLRN.Application");
                //从进程中获取正在运行的PCDMIS程序

                comObj = Activator.CreateInstance(comType);
                //创建一个实例。

                Application = comObj as PCDLRN.Application;
                //将这个实例强制转换成 PCDMIS的Application对象。

                PartProgram = Application.ActivePartProgram;
                //获取到Application对象当前处于激活状态的 PartProgram对象。

                if (PartProgram != null)
                {
                    //如果PartProgram对象不为空。

                    Commands = PartProgram.Commands;
                    //获取到Commands对象。
                    // Debug.WriteLine(Commands.Count);
                    PCdmisState = true;
                }



                else
                {
                    PCdmisState = false;
                    return null;
                }


            }
            catch (System.Exception em)
            {
                PCdmisState = false;
                return null;
            }

            return Commands;
        }
    }
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|计量论坛 ( 闽ICP备06005787号-1—304所 )
电话:0592-5613810 QQ:473647 微信:gfjlbbs闽公网安备 35020602000072号

GMT+8, 2025-6-16 10:20

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表