Your Products have been synced, click here to refresh
CodeWarrior Kp61dude!
I updated my code to remove Global variables and pass arguments instead. I also added some extra functionality so that it can totally replace all shortcuts for the operator and they can use only my program and I used some code suggested here. I still hit the same road block as before though. The event handler is giving me trouble. I found some code in a repository that does exactly what I need. It works perfect in excel but when I transfer it to visual studio, it only opens PC-Dmis. This is the excel code...
Dim PCDApp As PCDLRN.Application Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents Sub Start() HideExcel End Sub Private Sub HideExcel() Dim intAnswer As Integer intAnswer = MsgBox("Do you want to make Excel invisible? For this test, you should click Yes. It will become visible when you open a part program.", vbYesNo, "Hide Excel?") If intAnswer = vbYes Then Application.Visible = False Else Application.Visible = True End If LaunchPCDMIS End Sub Sub LaunchPCDMIS() Set PCDApp = CreateObject("PCDLRN.Application") Set AppEvents = PCDApp.ApplicationEvents PCDApp.Visible = True End Sub Private Sub AppEvents_OnOpenPartProgram(ByVal PartProg As PCDLRN.IPartProgram) [COLOR=#e74c3c]Hangles AppEvents.OnOpenPartProgram[/COLOR] ' Event subroutine. This activates when you OPEN a part program. Set PartProg = PCDApp.ActivePartProgram Application.Visible = True MsgBox "Part Program " & PartProg.Name & " opened. Excel should also be visible." End Sub Private Sub AppEvents_OnStartExecution(ByVal PartProg As PCDLRN.IPartProgram) [COLOR=#e74c3c]Handles AppEvents.OnStartExecution[/COLOR] ' Event subroutine. This activates when you START EXECUTION of the part program. MsgBox "STARTING EXECUTION OF " & PartProg.Name & ". Click OK to continue." End Sub Private Sub AppEvents_OnEndExecution(ByVal PartProg As PCDLRN.IPartProgram, ByVal TerminationType As Long) [COLOR=#e74c3c]Handles AppEvents.OnEndExecution[/COLOR] ' Event subroutine. This activates when you END EXECUTION of the part program. MsgBox "ENDING EXECUTION OF " & PartProg.Name & ". Click OK to continue." End Sub
I've tried to remove the excel portion of this and launch LaunchPCDMIS through a button and it doesn't work. Does anyone have any advice on how to update this code to be current? FYI, I removed the "Set" before every variable and surrounded the MsgBox with ()
My end goal here is when PC-Dmis starts running a program it will disable the buttons on my form so someone can't open something over top the running program and when the execution ends it enables the buttons. If I can only get the event handler to work I could get the rest done.
Thanks again for your help guys
Imports PCDLRN Public Class Form1 ' Globals Dim oPcd As Application = New Application() Dim WithEvents AppEvent As ApplicationObjectEvents Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim oPart As PartProgram = oPcd.ActivePartProgram AppEvent = oPcd.ApplicationEvents End Sub Private Sub AppEvents_OnOpenPartProgram(ByVal partProg As PartProgram) [COLOR=#e74c3c]Handles AppEvent.OnOpenPartProgram[/COLOR] partProg = oPcd.ActivePartProgram MsgBox("Part: " & partProg.Name & " opened.") End Sub End Class
It looks like operator but you can still access the edit window if you go through the menu View-Edit Window. IF PC-Dmis is already open, this doesn't happen.
Private Sub File_Explorer_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim varSourceopen As String = "Opened" If Process.GetProcessesByName("PCDLRN").Length = 0 Then Process.Start("C:\Program Files\Hexagon\PC-DMIS 2017 R2 64-bit\PCDLRN.exe", "/o") End If Do If Process.GetProcessesByName("PCDLRN").Length > 0 Then PCDApp = CreateObject("PCDLRN.Application") AppEvent = PCDApp.ApplicationEvents PCDApp.OperatorMode = True Exit Do Else Threading.Thread.Sleep(1000) End If Loop PCD_Create(varSourceopen) End Sub
Private Sub AppEvents_OnStartExecution(ByVal PartProg As PartProgram) Handles AppEvent.OnStartExecution ' Event subroutine. This activates when you START EXECUTION of the part program. Button1.Enabled = False Button2.Enabled = False Me.Close() End Sub
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |