Home Image-Pro Automation (Macros, Apps, Reports)

Problem with FILE LOCKED when PREMIER 9.2 attempts to save an open image . . .

All --

I have a problem with WINDOWS 7 and PREMIER 9.2 locking a file and not allowing my CODE to save an image.

The PCCA_SaveImage Subroutine (below) is meant to save the results of a multi step process.  The name of the step is passed to the routine and then the routine builds the name for the image and performs a SAVE AS.

The first time this is done the source image is a JPG IMAGE.  In the past I had to do some somersaults to get PREMIER to save the image properly.  I have used that code in the routine below.  The first time that the routine runs on an image (like the -B image) everything works fine.

If I run the routine a second time, the following error message is generated.



If I try to KILL the file before the SAVEAS, the KILL is not successful.

I have tried waiting 10 seconds between runs of the ROUTINE but the LOCK does not seem to be release.

I think I can work around this by saving the image to TEMP.TIF, closing the image, then renaming TEMP.TIF to the file name I originally wanted to use.  This would be clunky and I would like to know if there is another way to resolve this.

Your assistance would be much appreciated.

-- Matt 

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


    Private Sub PCCA_SaveImage(My_PhaseLetter As String)

        'Set up ERROR HANDLING
        On Error Resume Next

        'Connect with the ACTIVE IMAGE
        Dim doc1
        With Application.DocumentCommands.Active(Nothing)
            .Run(doc1)
        End With

        'Create the FULL FILE NAME
        Dim My_FullFileName As String = _
            textBox_Image.Text & _
            " + PCCA-" & My_PhaseLetter & _
            ".tif"

        'Workaround to save JPG image to TIF file with calibration, switch to TIF writer
        ThisApplication.ActiveImage.File.Format = _
            "tif"

        'Set IMAGE FULL FILE NAME
        ThisApplication.ActiveImage.File.FullPathName = _
            My_FullFileName

        'Call the SAVE AS function
        With Application.DocumentCommands.SaveAs(Nothing)
            .FileName = _
                My_FullFileName
            .Run(doc1)
        End With

        'Call the routine to perform the OPEN IMAGE
        PCCA_OpenImage(My_PhaseLetter)

    End Sub

Answers

  • 2017-02-16-173756 --

    All --

    Below is the PCCA_OpenImage Subroutine that is called to OPEN the IMAGES generated by the PCCA_SaveImage Subroutine.

    Maybe there is something in this that is generating the LOCK that the SAVEAS is having a problem with.

    Thanks.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
        Private Sub PCCA_OpenImage(My_PhaseLetter As String)
    
            'Create the FULL FILE NAME
            Dim My_FullFileName As String = _
                textBox_Image.Text & _
                " + PCCA-" & My_PhaseLetter & _
                ".tif"
    
            'Close all open images without prompting user
            CloseAllForm.ClosingAllAction=CloseAllForm.CloseAllFormAction.actionNoAll
            ThisApplication.Windows.CloseAll()
    
            'Open the file selected by the user
            Dim list1 = New List(1)
            With Application.DocumentCommands.OpenImage(Nothing)
                .Filenames = New String() {My_FullFileName}
                .Visible = True
                .Run(list1)
            End With
    
            'Trigger the TILE function to make this image as big as possible
            Application.MDICommands.TileVertically(Nothing).Run()
    
        End Sub

  • Matt,

    I believe this is fixed in Premier 9.3.

    Pierre
  • 2017-02-16-174843

    Pierre --

    Thank you for the information.

    I have patched it as I suggested (SAVEAS TEMP.TIF, DELETE IMAGE.TIF, RENAME TEMP.TIF to IMAGE.TIF) and it works. 

    Since I think the PREMIER CUSTOMER that will be using this has 9.2 in their organization and their IT DEPT has not put their seal of approval on 9.3 I'll leave the patch in place.  This should work when they migrate to 9.3 so all should be well.

    The version of PCCA_SaveImage that works with 9.2 is below.

    Thank you for your assistance.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

        Private Sub PCCA_SaveImage(My_PhaseLetter As String)
    
            'Set up ERROR HANDLING
            On Error Resume Next
    
            'Connect with the ACTIVE IMAGE
            Dim doc1
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            'Create the FULL FILE NAME
            Dim My_FullFileName As String = _
                textBox_Image.Text & _
                " + PCCA-" & My_PhaseLetter & _
                ".tif"
    
            'Workaround to save JPG image to TIF file with calibration, switch to TIF writer
            ThisApplication.ActiveImage.File.Format = _
                "tif"
    
            'Set IMAGE FULL FILE NAME
            ThisApplication.ActiveImage.File.FullPathName = _
                My_FullFileName
    
    '        -- Commented out because of glitch in 9.2 --
    '        Call the SAVE AS function
    '        With Application.DocumentCommands.SaveAs(Nothing)
    '            .FileName = _
    '                My_FullFileName
    '            .Run(doc1)
    '        End With
    
    '        -- Workaround because of glitch in 9.2 - START --
    
            'Create TEMP FILE NAME
            Dim My_TempFullFileName As String = _
                MacroDir & _
                "\Temp" & _
                ".tif"
    
            'Call the SAVE AS function
            With Application.DocumentCommands.SaveAs(Nothing)
                .FileName = _
                    My_TempFullFileName
                .Run(doc1)
            End With
    
            'Close all open images without prompting user
            CloseAllForm.ClosingAllAction=CloseAllForm.CloseAllFormAction.actionNoAll
            ThisApplication.Windows.CloseAll()
    
            'Delete the DESTINATION FILE
            Kill _
                My_FullFileName
    
            'Rename the TEMP FILE to the DESTINATION FILE
            Rename _
                My_TempFullFileName, _
                My_FullFileName
    
    '        -- Workaround because of glitch in 9.2 - END --
    
            'Call the routine to perform the OPEN IMAGE
            PCCA_OpenImage(My_PhaseLetter)
    
        End Sub
    

  • 2018-11-13-193310

    All --

    This FILE LOCKING ISSUE still seems to be a problem in 10.0.1.

    If I open IMAGE A.TIF with ROUTINE B I do not seem to be able to do a SAVEAS with the same name in another ROUTINE C without IMAGE-PRO complaining that the FILE IS LOCKED.

    I do not want to save it as TEMP.TIF and then close A.TIF and rename TEMP.TIF to A.TIF and then reopen A.TIF because I will lose the ZOOM and PAN that was active when the SAVE was triggered.

    Any suggestions on how to resolve this?

    Thanks.

    -- Matt
  • Matt,

    It seems to be OK as long as you do a Save rather than Save As.

    Pierre
  • 2018-11-16-093501

    Pierre --

    Thank you for the response and the suggestion.

    I think I tried to use SAVE vs SAVE AS but it is possible that I did not.

    I will be working on this project today and hopefully SAVE will not have the same issue.

    Loosing the ZOOM, PAN, and SCROLL when the IMAGE is saved is a bit of a headache.

    Thanks again.

    -- Matt
Sign In or Register to comment.