Opening a program in Operator Mode with Visual Basic

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Opening a program in Operator Mode with Visual Basic

    I am working on a new project where I create a visual basic form that allows the user to select the .prg file from the network and the script will save the .prg and .cad file to a local folder, if it doesn't already exist, then open that program automatically in PC-Dmis in operator mode so all they have to do is select the marked set and run. I have everything working except having the program open in Operator Mode. Everytime I try, it opens online mode. I read somewhere that there is a text file that you can create that allows you to open PC-Dmis, but it doesn't state how to get a program to open in it. Here is my code. Any help would be greatly appreciated. I will include the full code with file copy, but the PC-DMIS related code at the end is all I really need help with.

    Code:
    Public Class File_Explorer
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    OpenFileDialog1.InitialDirectory = "C:\Test\Approved"
    OpenFileDialog1.Title = "Find your Program"
    OpenFileDialog1.Filter = ".PRG files|*.prg"
    OpenFileDialog1.Multiselect = False
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    Dim sourceDir As String = OpenFileDialog1.FileName 'Sets 'sourceDir' to the location of the selected PRG file
    Dim sourceFileName As String = Dir(sourceDir) 'Extracts PRG file name from path
    Dim cadDir As String = IO.Path.ChangeExtension(sourceDir, ".CAD") 'Sets 'cadDir' to the location of the selected CAD file
    Dim cadFileName As String = Dir(cadDir) 'Extracts CAD file name from path
    
    Dim destDir As String = IO.Path.Combine("C:\Test\CMM Programs\", sourceFileName) 'Get PRG Destination Path
    Dim destCADDir As String = IO.Path.Combine("C:\Test\CMM Programs\", cadFileName) 'Get CAD Destination Path
    
    If My.Computer.FileSystem.FileExists(destCADDir) Then
    'Do nothing and move on
    Else
    'Copy file
    IO.File.Copy(cadDir, destCADDir)
    End If
    
    If My.Computer.FileSystem.FileExists(destDir) Then
    'Do nothing and move on
    Else
    'Copy file
    IO.File.Copy(sourceDir, destDir)
    End If
    
    Dim PCDApp, PCDPartPrograms
    
    PCDApp = CreateObject("PCDLRN.Application")
    PCDPartPrograms = PCDApp.PartPrograms
    
    PCDApp.Visible = True
    PCDPartPrograms.Open(destDir, "Offline")
    End If
    
    End Sub

  • #2
    Problem solved. The only "bug" that I have witnessed so far is if you manually exit a program and you have the Open search box open inside of PC-Dmis while running the scirpt, the script will still work as desired but the Open search box will also stay open. Not a huge deal, but if anyone knows how to exit the open search box, this would be more robust. Full code

    Code:
    Public Class File_Explorer
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim PCDApp, PCDPartProgram, PCDPartPrograms
    
    PCDApp = CreateObject("PCDLRN.Application")
    PCDPartPrograms = PCDApp.PartPrograms
    If PCDApp.Visible = True Then
    PCDPartProgram = PCDApp.ActivePartProgram
    On Error Resume Next
    PCDPartProgram.Close()
    End If
    
    If PCDApp.Visible = False Then
    PCDApp.OperatorMode = True
    PCDApp.Visible = True
    End If
    
    OpenFileDialog1.InitialDirectory = "C:\Test\Approved"
    OpenFileDialog1.Title = "Find your Program"
    OpenFileDialog1.Filter = ".PRG files|*.prg"
    OpenFileDialog1.FileName = ""
    OpenFileDialog1.Multiselect = False
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    Dim sourceDir As String = OpenFileDialog1.FileName 'Sets 'sourceDir' to the location of the selected PRG file
    Dim sourceFileName As String = Dir(sourceDir) 'Extracts PRG file name from path
    Dim cadDir As String = IO.Path.ChangeExtension(sourceDir, ".CAD") 'Sets 'cadDir' to the location of the selected CAD file
    Dim cadFileName As String = Dir(cadDir) 'Extracts CAD file name from path
    
    Dim destDir As String = IO.Path.Combine("C:\Test\CMM Programs\", sourceFileName) 'Get PRG Destination Path
    Dim destCADDir As String = IO.Path.Combine("C:\Test\CMM Programs\", cadFileName) 'Get CAD Destination Path
    
    If My.Computer.FileSystem.FileExists(destCADDir) Then
    'Do nothing and move on
    Else
    'Copy file
    IO.File.Copy(cadDir, destCADDir)
    End If
    
    If My.Computer.FileSystem.FileExists(destDir) Then
    'Do nothing and move on
    Else
    'Copy file
    IO.File.Copy(sourceDir, destDir)
    End If
    
    If PCDApp.Visible = False Then
    PCDApp.OperatorMode = True
    PCDApp.Visible = True
    End If
    
    PCDPartPrograms.Open(destDir, "Offline")
    
    Me.Close()
    
    End If
    
    End Sub
    
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim PCDApp, PCDPartProgram, PCDPartPrograms
    
    PCDApp = CreateObject("PCDLRN.Application")
    PCDPartPrograms = PCDApp.PartPrograms
    If PCDApp.Visible = True Then
    PCDPartProgram = PCDApp.ActivePartProgram
    On Error Resume Next
    PCDPartProgram.Close()
    End If
    
    If PCDApp.Visible = False Then
    PCDApp.OperatorMode = True
    PCDApp.Visible = True
    End If
    
    OpenFileDialog1.InitialDirectory = "C:\Test\Unproven"
    OpenFileDialog1.Title = "Find your Program"
    OpenFileDialog1.Filter = ".PRG files|*.prg"
    OpenFileDialog1.FileName = ""
    OpenFileDialog1.Multiselect = False
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    Dim sourceDir As String = OpenFileDialog1.FileName 'Sets 'sourceDir' to the location of the selected PRG file
    Dim sourceFileName As String = Dir(sourceDir) 'Extracts PRG file name from path
    Dim cadDir As String = IO.Path.ChangeExtension(sourceDir, ".CAD") 'Sets 'cadDir' to the location of the selected CAD file
    Dim cadFileName As String = Dir(cadDir) 'Extracts CAD file name from path
    
    Dim destDir As String = IO.Path.Combine("C:\Test\CMM Programs\", sourceFileName) 'Get PRG Destination Path
    Dim destCADDir As String = IO.Path.Combine("C:\Test\CMM Programs\", cadFileName) 'Get CAD Destination Path
    
    If My.Computer.FileSystem.FileExists(destCADDir) Then
    'Do nothing and move on
    Else
    'Copy file
    IO.File.Copy(cadDir, destCADDir)
    End If
    
    If My.Computer.FileSystem.FileExists(destDir) Then
    'Do nothing and move on
    Else
    'Copy file
    IO.File.Copy(sourceDir, destDir)
    End If
    
    If PCDApp.Visible = False Then
    PCDApp.OperatorMode = True
    PCDApp.Visible = True
    End If
    
    PCDPartPrograms.Open(destDir, "Offline")
    
    Me.Close()
    
    End If
    
    End Sub
    End Class
    I have 2 buttons. One for the Approved and proved out programs and the Unproven, which are the programs that have not been ran yet, have been edited, etc. Select the button you want, search for your program on the network, open it, the script will save it to a local directory of your choice if it doesn't already exist and open the program in operator mode.

    Comment

    Related Topics

    Collapse

    Working...
    X