Disk read error? Can't open master program after using auto save script.

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

  • Disk read error? Can't open master program after using auto save script.

    UPDATE: The issue was actually caused by a set up document being altered. (See post #15)



    Morning guys and girls, I'm having a bit of an issue with opening several of my programs after using a BASIC script to serialize and auto save. When trying to open the master I get a pop up saying "A disk error occurred during a read operation", it doesn't happen all the time but enough for it to be an issue. I then have to quit the program and restart PC-DMIS to try and open an archived copy.

    Any ideas to what could be causing this? I am using a script to auto save so my gut is telling me it could be that because I have little to no experience in scripting! But I also made a change to include set up documents in the program and this seems to be where the loading operation fails?

    Below is my script for autosaving,

    Code:
    Sub main()
    
    Dim archivePath
    archivePath = "C:\CMM_2\ROLLS ROYCE\746B\RC\2017"
    
    
    
    
    
    Dim pcapp As Object
    Set pcapp = createobject("pcdlrn.application")
    
    Dim pcpart As Object
    Set pcpart = pcapp.activepartprogram
    
    pcpart.save
    
    
    Dim source_path
    source_path = pcpart.fullname
    
    
    Dim progname
    progname = left(pcpart.Name,len(pcpart.Name)-4)
    
    Dim rc
    rc=""
    
    Dim myrc As Object
    Set myrc = pcpart.GetVariableValue("R_C")
    If Not myrc is Nothing Then
    rc = myrc.stringvalue
    End If
    
    Dim SN
    SN=""
    
    Dim mysn As Object
    Set mysn = pcpart.GetVariableValue("S_N")
    
    If Not mysn is Nothing Then
    SN = mysn.stringvalue
    End If
    
    
    
    Dim fso As Object
    Set fso = createobject("scripting.filesystemobject")
    
    
    Dim ofolder As Object
    
    If Not fso.folderexists(archivepath) Then
    Set ofolder = fso.createfolder(archivepath)
    End If
    
    If Not fso.folderexists(archivepath & "\" & rc) Then
    Set ofolder = fso.createfolder(archivepath & "\" & rc)
    End If
    
    
    dest_path = archivepath & "\" & rc & "\" & progname & "RC_" & rc & "_SN_" &  SN & ".prg"
    'MsgBox(dest_path)
    
    
    
    
    fso.copyfile source_path, dest_path
    
    
    
    
    Set fso = Nothing
    Set pcpart = Nothing
    Set pcapp = Nothing
    
    
    End Sub
    Any help would be massively appreciated!



    Untitled.jpg
    Last edited by JackMido; 02-22-2018, 08:06 AM.
    Clearance is clearance.

  • #2
    As far as I can understand that script, it is trying to copy the original program to another folder, with a modified name. But, it is doing it while PC-DMIS still has the original program open - this can never have worked?? Have you lost a pcpart.close somewhere?

    I would suggest doing a pcpart.SaveAs(new name/path) followed by a pcpart.SaveAs(original name/path) instead of using the fso.
    AndersI
    SW support - Hexagon Metrology Nordic AB

    Comment


    • #3
      That is how I understand the program working, I'm really new to scripting (and CMM in general) so this is just a modified version of scripts I have found on here. It is working fine for 99% of parts and has been doing for the past few months but now this issue seems to be cropping up out of nowhere?

      I will try using a SaveAs like suggested, it isn't a consistent error though so I may not have an answer on whether or not it has worked for a few days but thank you for taking the time to look at it.

      I have just looked through some of my other scripts and there isn't a pcpart.close in any of them, just to check I am understanding it would you use a pcpart.close after saving the modified name and then pcpart.open? to re-open the master?

      EDIT:

      I have just tried doing a pcpart.SaveAs as suggested and the process works fine until I quit the master program and try to reopen and then the same error occurs as before?


      Code:
      Sub main()
      
      Dim archivePath
      archivePath = "C:\CMM_2\ROLLS ROYCE\746B\RC\2018"
      
      
      Dim pcapp As Object
      Set pcapp = createobject("pcdlrn.application")
      
      Dim pcpart As Object
      Set pcpart = pcapp.activepartprogram
      
      pcpart.save
      
      
      Dim source_path
      source_path = pcpart.fullname
      
      
      Dim progname
      progname = left(pcpart.Name,len(pcpart.Name)-4)
      
      Dim rc
      rc=""
      
      Dim myrc As Object
      Set myrc = pcpart.GetVariableValue("R_C")
      If Not myrc is Nothing Then
      rc = myrc.stringvalue
      End If
      
      Dim SN
      SN=""
      
      Dim mysn As Object
      Set mysn = pcpart.GetVariableValue("S_N")
      
      If Not mysn is Nothing Then
      SN = mysn.stringvalue
      End If
      
      
      
      Dim fso As Object
      Set fso = createobject("scripting.filesystemobject")
      
      
      Dim ofolder As Object
      
      If Not fso.folderexists(archivepath) Then
      Set ofolder = fso.createfolder(archivepath)
      End If
      
      If Not fso.folderexists(archivepath & "\" & rc) Then
      Set ofolder = fso.createfolder(archivepath & "\" & rc)
      End If
      
      
      dest_path = archivepath & "\" & rc & "\" & progname & "RC_" & rc & "_SN_" &  SN & ".prg"
      
      
      bolPassFail = pcpart.SaveAs(dest_path)
      
      bolPassFail = pcpart.SaveAs(source_path)
      
      Set fso = Nothing
      Set pcpart = Nothing
      Set pcapp = Nothing
      
      
      End Sub


      p.s Thanks for the suggestion of Save As I didn't realise that would save the CAD as well! My employer wanted a CAD back up with every single part so that was going to be my next mission!
      Last edited by JackMido; 01-12-2018, 06:55 AM. Reason: Updating after changing script
      Clearance is clearance.

      Comment


      • #4
        I don't see a problem with the script.

        It first saves the part program.

        Then it copies the file.

        This is how mine works - I hazard a guess that this is derived from mine based on some of the naming conventions.


        Any special characters in either of the variables you pull in?
        Automettech - Automated Metrology Technology

        Comment


        • #5
          I think it is a rare hybrid of yours and vpt.se if I can remember rightly!

          No special characters, one is a 10 digit number and the second is a 4 digit number.

          I could be barking up the wrong tree with the script and it could be something unrelated that is causing it?
          Clearance is clearance.

          Comment


          • #6
            PC-DMIS (or Windows) doesn't always release the filehandle for programs (read:files) that has been closed, I don't know why this happens.

            If you always get this error on opening the master program (after you have run the script), this might be the culprit. It happens during "normal" PC-DMIS usage as well. When you close PC-DMIS, the handle gets released. Next time this happens, try to rename your master program from Windows Explorer, if the filehandle is locked, it should not let you rename it, then you should suspect that PC-DMIS still has the program in it's grips and the only way to "free" it is by closing PC-DMIS, thus releasing the handle.

            Just a tip.
            Last edited by vpt.se; 01-12-2018, 08:05 AM.
            PC-DMIS CAD++ 2o19 R1 SP3

            Comment


            • #7
              Thanks for the replies guys, I just tried to force it into an error to try your tip vpt but it actually worked fine this time!

              That's my cue to leave it and run away for the weekend! Have a good one everyone and thanks for your help.
              Clearance is clearance.

              Comment


              • #8
                I couldn't leave it for the weekend it was bugging me waaay too much! So just as an update.... I have managed to force it into the error again! I then found the program in file explorer (Windows) and I can freely change the filename whilst the error is still active. Any ideas on where to go from here?
                Clearance is clearance.

                Comment


                • #9
                  Well, then it's not the filehandle issue.

                  Maybe your two SaveAs' (saveasses?) conflict with each other (ie. script execution is so fast that your HDD can't keep up thus popping the error)? Try commenting the sourcepath SaveAs out and try triggering the error again?
                  PC-DMIS CAD++ 2o19 R1 SP3

                  Comment


                  • #10
                    Sorry for the late reply mate, I tried commenting out a SaveAss and it still brought up the error. Does anyone have any ideas on what else could be causing it to error out? It could be nothing to do with the script? Or any ideas of a workaround?
                    Clearance is clearance.

                    Comment


                    • #11
                      Insert some messageboxes after everyone of your CreateFolder and SaveAs to pinpoint where the readerror occurs (for debugging purposes).
                      PC-DMIS CAD++ 2o19 R1 SP3

                      Comment


                      • #12
                        I have added them in now, but the program is error-ing out when loading the master which (should be) unaffected by any bugs within the script itself right? Once loaded and ran I can run the program several times and get no errors from the script its only when I exit the program and try to reload that I'm hit with an error. Not trying to knock your suggestion I'm just trying to wrap my head around scripting lol
                        Clearance is clearance.

                        Comment


                        • #13
                          Ok, so the error pops up when loading the master program in PC-DMIS (from the "Open" menu)? If so, then it doesn't seem like the script is the culprit, unless it is locking the master somehow. Which one of the three programs referred to in your script is the master?

                          Is it the program referred to at pcpart.save or the ones referred to at bolPassFail = pcpart.SaveAs(dest_path) or at bolPassFail = pcpart.SaveAs(source_path)?
                          PC-DMIS CAD++ 2o19 R1 SP3

                          Comment


                          • #14
                            Yeah basically I run the program as usual and then save and quit and all is fine. Then the next time the job rolls around I do file-> Open-> master program and it pops up the read error.

                            The master is the one referred to at pcpart.save and bolPassFail=pcpart.SaveAs(source_path), originally I didn't have the double SaveAsses in the script I have changed them based on a suggestion on this thread, I was using pcpart.save and then an fso.copyfile and modifying the name during the copy.
                            Clearance is clearance.

                            Comment


                            • #15
                              UPDATE: Just updating this in case anyone faces the same problem in the future.

                              It seems like my issue wasn't with the script but with the set up document I had in the program, I had displayed as a link and someone had edited the document through the link and not the original document. Since I've stopped displaying as a link and just use the original document everything seems to be running fine!

                              Thanks to everyone that helped, you guys are amazing!
                              Clearance is clearance.

                              Comment

                              Related Topics

                              Collapse

                              Working...
                              X