Your Products have been synced, click here to refresh
' Globals Private busy As Boolean = False Private complete As Boolean = True Private PCDApp As PCDLRN.Application = Nothing ' take advantage of intellisence by using this method of instantiating. Private PCDPartPrograms As PCDLRN.PartPrograms Private PCDPartProgram As PCDLRN.PartProgram = Nothing Private destDir As String = "" Dim destCADDir As String = "" Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Dim PCDApp, PCDPartProgram, PCDPartPrograms PCDApp = CreateObject("PCDLRN.Application") '<-- if Pcdmis is not running this will start it, if open then it'll only attach to it. PCDPartPrograms = PCDApp.PartPrograms 'If PC-DMIS is open, close current program If PCDApp.Visible = True Then ' <-- if Pcdmis is NOT hidden then PCDPartProgram = PCDApp.ActivePartProgram ' <-- attach exe to currently opened part program 'On Error Resume Next ' <-- it'll make you a better dev if you avoid these. 'PCDPartProgram.Close() ' you're closing current part program...why? End If 'If PC-DMIS is not open, open operator mode If PCDApp.Visible = False Then ' <-- if Pcdmis IS hidden then PCDApp.OperatorMode = True ' <-- switching modes (I've never tested this, so no input to give) PCDApp.Visible = True ' <-- making Pcdmis visible if hidden End If Dim OpenFileDialog1 As New OpenFileDialog() OpenFileDialog1.InitialDirectory = "ORIGINAL FILE DIRECTORY HERE" 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 destCADDir = IO.Path.Combine("C:\CMM\", cadFileName) 'Get CAD Destination Path destDir = IO.Path.Combine("C:\CMM\", sourceFileName) 'Get PRG Destination Path Dim t As Threading.Thread If Not busy Then t = New Threading.Thread(AddressOf MyThread) End If 'If the CAD file doesn't already exist in new directory, then copy the file If Not My.Computer.FileSystem.FileExists(destCADDir) Then 'Copy file 'IO.File.Copy(cadDir, destCADDir) End If 'If the PRG file doesn't already exist in new directory, then copy the file If Not My.Computer.FileSystem.FileExists(destDir) Then 'Copy file 'IO.File.Copy(sourceDir, destDir) End If 'If PC-DMIS is not open, open operator mode If PCDApp.Visible = False Then PCDApp.OperatorMode = True PCDApp.Visible = True End If ' Start FileIO thread If Not busy Then busy = True t.Start() End If 'Closes the form 'Me.Close() ' you want to hide maybe? 'Me.Hide() End If End Sub Private Sub MyThread() If busy And complete Then complete = False 'Check if both PRG and CAD files exists. If they do, open the PRG. If not, wait 1 sec and loop While busy If My.Computer.FileSystem.FileExists(destDir) And My.Computer.FileSystem.FileExists(destCADDir) Then PCDPartPrograms.Open(destDir, "CMM1") busy = False complete = True 'Me.Show() ' causes a crss thread error FYI Exit While Else Threading.Thread.Sleep(1000) End If End While End If End Sub
' Globals Private busy As Boolean = False Private complete As Boolean = True Private PCDApp As PCDLRN.Application = Nothing ' take advantage of intellisence by using this method of instantiating. Private PCDPartPrograms As PCDLRN.PartPrograms Private PCDPartProgram As PCDLRN.PartProgram = Nothing Private destDir As String = "" Dim destCADDir As String = "" Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Dim PCDApp, PCDPartProgram, PCDPartPrograms PCDApp = CreateObject("PCDLRN.Application") '<-- if Pcdmis is not running this will start it, if open then it'll only attach to it. PCDPartPrograms = PCDApp.PartPrograms 'If PC-DMIS is open, close current program If PCDApp.Visible = True Then ' <-- if Pcdmis is NOT hidden then PCDPartProgram = PCDApp.ActivePartProgram ' <-- attach exe to currently opened part program 'On Error Resume Next ' <-- it'll make you a better dev if you avoid these. 'PCDPartProgram.Close() ' you're closing current part program...why? End If 'If PC-DMIS is not open, open operator mode If PCDApp.Visible = False Then ' <-- if Pcdmis IS hidden then PCDApp.OperatorMode = True ' <-- switching modes (I've never tested this, so no input to give) PCDApp.Visible = True ' <-- making Pcdmis visible if hidden End If Dim OpenFileDialog1 As New OpenFileDialog() OpenFileDialog1.InitialDirectory = "ORIGINAL FILE DIRECTORY HERE" 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 destCADDir = IO.Path.Combine("C:\CMM\", cadFileName) 'Get CAD Destination Path destDir = IO.Path.Combine("C:\CMM\", sourceFileName) 'Get PRG Destination Path Dim t As Threading.Thread If Not busy Then t = New Threading.Thread(AddressOf MyThread) End If 'If the CAD file doesn't already exist in new directory, then copy the file If Not My.Computer.FileSystem.FileExists(destCADDir) Then 'Copy file 'IO.File.Copy(cadDir, destCADDir) End If 'If the PRG file doesn't already exist in new directory, then copy the file If Not My.Computer.FileSystem.FileExists(destDir) Then 'Copy file 'IO.File.Copy(sourceDir, destDir) End If 'If PC-DMIS is not open, open operator mode If PCDApp.Visible = False Then PCDApp.OperatorMode = True PCDApp.Visible = True End If ' Start FileIO thread If Not busy Then busy = True t.Start() End If 'Closes the form 'Me.Close() ' you want to hide maybe? 'Me.Hide() End If End Sub Private Sub MyThread() If busy And complete Then complete = False 'Check if both PRG and CAD files exists. If they do, open the PRG. If not, wait 1 sec and loop While busy If My.Computer.FileSystem.FileExists(destDir) And My.Computer.FileSystem.FileExists(destCADDir) Then PCDPartPrograms.Open(destDir, "CMM1") busy = False complete = True 'Me.Show() ' causes a crss thread error FYI Exit While Else Threading.Thread.Sleep(1000) End If End While End If End Sub
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |