hexagon logo

Partprograms.open scripting error

Ok so I have stolen some code from here on using a script to open a program and run it, then closes the program. It runs and works perfectly... UNTIL I try to make the filepath variable, such as ("C:\Users\Public\Desktop" + strID ) so that I can use a barcode scanner to input the last bit of filepath into the script and execute that way. I keep getting an error message on the PCDpartprogams.open line stating "wrong number of dimensions". Any ideas?


Found this in my repository...


Dim PCDApp, PCDPartPrograms, PCDPartProgram

Set PCDApp = CreateObject("PCDLRN.Application")
Set PCDPartPrograms = PCDApp.PartPrograms

PCDApp.Visible = True
PCDPartPrograms.Open "Z:\test1.PRG", "CMM1"

Set PCDPartProgram = PCDApp.ActivePartProgram

'msgbox "This will start the execution of the partprogram!"
PCDPartProgram.Execute

' PC-DMIS executes the partprogram

PCDPartProgram.Close

' PC-DMIS closes and saves the partprogram

PCDPartPrograms.Open "Z:\test2.PRG", "CMM1"

Set PCDPartProgram = PCDApp.ActivePartProgram

'msgbox "This will start the execution of the partprogram!"
PCDPartProgram.Execute

' PC-DMIS executes the partprogram

PCDPartProgram.Close

' PC-DMIS closes and saves the partprogram

' Cleanup
Set PCDPartProgram = nothing
Set PCDPartPrograms = nothing
Set PCDApp = nothing




This should (in theory) open "test1.prg", execute it, close and save and then open "test2.prg", execute it, close and save.
  • OK, so I finally figured it out, it works if a add "PCDApp." in front of the "PartsPrograms.Open" ".Execute", and ".Close"

    Sub main (strID As String)
    MsgBox strID
    Dim Fpath As String
    Dim PCDApp, PCDPartPrograms, PCDPartProgram
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Fpath = strID
    MsgBox Fpath
    PCDApp.Visible = True
    With PCDAPartPrograms
    PCDApp.PartPrograms.Open Fpath, "CMM1"
    
    Set PCDPartProgram = PCDApp.ActivePartProgram
    End With
    
    'MsgBox "This will start the execution of the partprogram!"
    PCDApp.ActivePartProgram.Execute
    
    ' PC-DMIS executes the partprogram
    
    PCDApp.ActivePartProgram.Close
    
    ' PC-DMIS closes And saves the partprogram
    
    'PCDPartPrograms.Open "Z:\test2.PRG", "CMM1"
    
    'Set PCDPartProgram = PCDApp.ActivePartProgram
    
    'MsgBox "This will start the execution of the partprogram!"
    ' PCDPartProgram.Execute
    
    ' PC-DMIS executes the partprogram
    
    ' PCDPartProgram.Close
    
    ' PC-DMIS closes And saves the partprogram
    
    ' Cleanup
    Set PCDPartProgram = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDApp = Nothing
    End Sub


    Thanks for all the help guys!