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;
}
}
}
|