hexagon logo

PC-DMIS Application Events via C#

So through the process of improving my app for automating pc-dmis I have undertaken the task of converting parts of my app from vbscripts to all C# code. When "interacting" with pc-dmis in previous versions, I would call the vbscripts to automate pc-dmis and wait for the script to finish before doing anything else.

Through converting my code in vbscripts to c# I have come across the problem that I don't know how to handle application events in c#. I am having trouble matching the syntax differences between vbscripts and c#.

The application event in particular i'm looking to handle is the "IsMachineConnected" event during startup of pc-dmis.

So if anyone has an example or input they'd like to share, I would greatly appreciate it.

Here is my working code to launch pc-dmis:
Using PCDLRN;

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]public[/FONT][/COLOR] [COLOR=#0000ff][FONT=Consolas]void[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]pcdLaunch[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]()[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]{[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]Type [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]PCDRLN_Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]null[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]object[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]PCDObj[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]null[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDLRN.Application[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]PCDApp[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]null[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]try[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]{[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDRLN_Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Type.GetTypeFromProgID[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#a31515][FONT=Consolas]"[/FONT][/COLOR][COLOR=#a31515][FONT=Consolas]PCDLRN.Application[/FONT][/COLOR][COLOR=#a31515][FONT=Consolas]"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]);[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDObj[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Activator.CreateInstance[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]PCDRLN_Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]);[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#0000ff][FONT=Consolas]catch[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] ([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]System.Exception[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]em[/FONT][/COLOR][COLOR=#000000][FONT=Consolas])[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]{[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]MessageBox.Show[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]em.Message[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]);[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDApp[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]new[/FONT][/COLOR] [COLOR=#000000][FONT=Consolas]PCDLRN.Application[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]();[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDApp.OperatorMode[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]true[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]

[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]PCDApp.Visible[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] = [/FONT][/COLOR][COLOR=#0000ff][FONT=Consolas]false[/FONT][/COLOR][COLOR=#000000][FONT=Consolas];[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]
[SIZE=12px][COLOR=#000000][FONT=Segoe UI][COLOR=#000000][FONT=Consolas]}[/FONT][/COLOR] [/FONT][/COLOR][/SIZE]


TIA
Parents
  • Reference the Interop.Pcdlrn library and type similar to the following... (minus the class stuff).

    using PCDLRN;
    
    namespace SmartPattern_PcdApp
    {
    	public partial class Form1 : Form
    	{
    		// Globals
    		ArrayList CmdItems = new ArrayList();
    		PcDmisCls oPcdApp = new PcDmisCls();
    
    		public Form1()
    		{
    			InitializeComponent();
    		}
    
    
    		private void Form1_Load(object sender, EventArgs e)
    		{			
    			PartProgram part = oPcdApp.Part();
    			EditWindow ew = oPcdApp.editWindow;			
    
    			oPcdApp.application.ApplicationEvents.OnSavePartProgram += new IApplicationEvents_OnSavePartProgramEventHandler(onSavePart);
    			part.OnAddObject += new IPartProgramEvents_OnAddObjectEventHandler(addedObject);			
    
    			part = null;
    			ew = null;			
    		}
    
    		// Triggers when part is saved...
    		void onSavePart(PartProgram prg)
    		{
    			// what do I put here?
    			MessageBox.Show("Part Saved!");
    		}
    
    		// Triggers when an object is added
    		void addedObject(Command cmd)
    		{
    			MessageBox.Show("Item: " + cmd.ID + " was added!");
    
    			// Create cmds in C
    		}
    		}
    
Reply
  • Reference the Interop.Pcdlrn library and type similar to the following... (minus the class stuff).

    using PCDLRN;
    
    namespace SmartPattern_PcdApp
    {
    	public partial class Form1 : Form
    	{
    		// Globals
    		ArrayList CmdItems = new ArrayList();
    		PcDmisCls oPcdApp = new PcDmisCls();
    
    		public Form1()
    		{
    			InitializeComponent();
    		}
    
    
    		private void Form1_Load(object sender, EventArgs e)
    		{			
    			PartProgram part = oPcdApp.Part();
    			EditWindow ew = oPcdApp.editWindow;			
    
    			oPcdApp.application.ApplicationEvents.OnSavePartProgram += new IApplicationEvents_OnSavePartProgramEventHandler(onSavePart);
    			part.OnAddObject += new IPartProgramEvents_OnAddObjectEventHandler(addedObject);			
    
    			part = null;
    			ew = null;			
    		}
    
    		// Triggers when part is saved...
    		void onSavePart(PartProgram prg)
    		{
    			// what do I put here?
    			MessageBox.Show("Part Saved!");
    		}
    
    		// Triggers when an object is added
    		void addedObject(Command cmd)
    		{
    			MessageBox.Show("Item: " + cmd.ID + " was added!");
    
    			// Create cmds in C
    		}
    		}
    
Children