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

CODE TO SET FULL FILE NAME (PATH & FILE & EXTENSION) FOR QUICK SAVE ANALYSIS AND PUBLICATION . . .

2020-09-11-174452

All --

The CODE below is embedded within an APP I wrote for an IMAGE-PRO PREMIER 9.3 user back in 2016.

They have asked me if we can alter the APP to give them more control of the names of the IMAGE FILES.

I know that if the

    IMAGE-PRO + FILE + OPTIONS + FILE + QUICK SAVE + PROMPT FOR FILE NAME OPTION

is activated, they will be prompted for the FILE NAME for the ANALYSIS IMAGE and then they will be prompted for the FILE NAME for the PUBLICATION IMAGE.

Is there a way for the CODE to set the FILE NAME that will be used?

I poked around in the HELP FILES and could not find an answer.

I tried

        ThisApplication.Settings("QuickSave","Publication").Set("File","aaa.jpg")
        ThisApplication.Settings("QuickSave","Analysis").Set("File","bbb.tif")
and

        ThisApplication.Settings("QuickSave","Publication").Set("Filename","aaa.jpg")
        ThisApplication.Settings("QuickSave","Analysis").Set("Filename","bbb.tif")

Neither of these worked.  IMAGE-PRO wanted to use the FILENAME that was already affiliated with the image.

I tried to change the DISPLAY NAME for the IMAGE but QUICK SAVE ignored the DISPLAY NAME and went somewhere else to get the name it uses.

Is there CODE that will allow me to use the QUICK SAVE FEATURE and a FILE NAME that my CODE sets independent of what the image has been saved as before (example with a DATE & TIME STAMP)?

Thanks in advance.

-- Matt

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



    Private Sub button_SaveImage_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button_SaveImage.Click

        'Declare LOCAL VARIABLES
        Dim imageA, docA, windowA
        Dim varList1 = New List(1)
        Dim varList2 = New List(1)

        'Set the DEFAULT PATH for the QUICK SAVE ANALYSIS and QUICK SAVE PUBLICATION
        ThisApplication.Settings("QuickSave","Publication").Set("Path",textBox_WorkingFolder.Text)
        ThisApplication.Settings("QuickSave","Analysis").Set("Path",textBox_WorkingFolder.Text)

        'Connect with the ACTIVE IMAGE
        With Application.DocumentCommands.ActiveImage(Nothing)
            .Run(imageA)
        End With

        With Application.DocumentCommands.Activate(Nothing)
            .Run(imageA, docA)
        End With

        With Application.WindowCommands.Define(Nothing)
            .Run(docA, windowA)
        End With

        'Perform the QUICK SAVE ANALYSIS
        With Application.WindowCommands.QuickSaveSelectedForAnalysis(Nothing)
            .Run(varList1)
        End With

        'Activate the APPROPRIATE IMAGE
        With Application.DocumentCommands.Activate(Nothing)
            .Run(imageA, docA)
        End With

        'Perform the QUICK SAVE ANALYSIS
        With Application.WindowCommands.QuickSaveSelectedForPublication(Nothing)
            .Run(varList2)
        End With

        'Activate the APPROPRIATE IMAGE
        With Application.DocumentCommands.Activate(Nothing)
            .Run(imageA, docA)
        End With

    End Sub


Answers

  • 2020-09-14-172934

    All --

    Any options here?

    I can change to other methods of saving the IMAGE in a TIF FILE and in a JPG FILE but hopefully I can tweak the existing code rather than rewriting this routine.

    Thanks.

    -- Matt


  • edited September 2020
    Hi Matt,

    If you want to prompt user to save image under user-defined name, then you should just use SaveAs command, like this:

        Public Function SaveForAnalysysWithPrompt() As SimpleScript
            SaveForAnalysysWithPrompt = New SimpleScript
            Dim image1, doc1
    
            With Application.DocumentCommands.ActiveImage(SaveForAnalysysWithPrompt)
                .Run(image1)
            End With
    
            With Application.DocumentCommands.SaveAs(SaveForAnalysysWithPrompt)
                .Filename = ""
                .Run(image1)
            End With
    
            With Application.DocumentCommands.Activate(SaveForAnalysysWithPrompt)
                .Run(image1, doc1)
            End With
    
        End Function
    
    

    It will cover saving to TIF or JPG. 
    If you want to have an equivalent of "Save for publication", then you should use "Snap" command (to burn all overlays in) and then SaveAs (close Snap image in the end).

        Public Function SaveForPublicationWithPrompt() As SimpleScript
            SaveForPublicationWithPrompt = New SimpleScript
            Dim window1, image1, doc1, window2, doc2
    
            With Application.WindowCommands.Active(SaveForPublicationWithPrompt)
                .Run(window1)
            End With
    
            With Application.WindowCommands.Snap(SaveForPublicationWithPrompt)
                .Run(window1, image1)
            End With
    
            With Application.DocumentCommands.Activate(SaveForPublicationWithPrompt)
                .Run(image1, doc1)
            End With
    
            With Application.DocumentCommands.SaveAs(SaveForPublicationWithPrompt)
                .Filename = ""
                .Run(image1)
            End With
    
            With Application.DocumentCommands.Activate(SaveForPublicationWithPrompt)
                .Run(doc1, doc1)
            End With
    
            With Application.WindowCommands.Define(SaveForPublicationWithPrompt)
                .Run(doc1, window2)
            End With
    
            With Application.WindowCommands.Close(SaveForPublicationWithPrompt)
                .Run(window2)
            End With
    
            With Application.DocumentCommands.Activate(SaveForPublicationWithPrompt)
                .Run(window1, doc2)
            End With
    
        End Function
    
    

    Yuri
  • 2020-09-15-142445

    Yuri --

    Thank you for the suggestions.

    This is a very confusing situation.

    I think the user came to me with a request to use the IMAGE NAME GENERATOR built into the CAMERA CAPTURE TOOL.

    For some reason when I wrote the APP for them back in 2016, I used the QUICK SAVE TOOL.  One call for ANALYSIS VERSION and on call for PUBLICATION VERSION.

    They have used the APP with the SAVING being done by the QUICK SAVE TOOL since 2016.  Now they would like to change the naming convention a bit beyond what the CAMERA CAPTURE TOOL will do for them.

    If I can feed a PATH (done) and FILENAME (not done) to the QUICK SAVE TOOL from CODE, all would be well with a minimum of rewrite.  If my CODE cannot control the FILENAME used by QUICK SAVE the the your SaveForAnalysis and SaveForPublication modified to accept a FILE NAME from my CODE will be a good plan.

    So . . .

    Is there a way for my CODE to send a PATH and FILE NAME to QUICK SAVE or is there an IMAGE PROPERTY that I can manipulate with my CODE that will be used by QUICK SAVE as the basis for the FILE NAME that it generates?

    Thanks.

    -- Matt


  • Hi Matt,

    If you want to use your old code for Quick save, then you can control Prefix of the file name from a macro:
        Sub SetQuickFilePrefix()
            ThisApplication.Settings("QuickSave","Publication").Set("Prefix","MyPublication")
            ThisApplication.Settings("QuickSave","Analysis").Set("Prefix","MyAnalysis")
        End Sub
    and the index will be generated automatically, if files with the same name already exist.

    For newly captured files you can also define DisplayName, which will then be used for QuickSave:
        Sub SetDisplayName
            ThisApplication.ActiveImage.DisplayName="MyNameForPublication"
        End Sub
    
    Note, that for images opened from files, QuickSave will try using existing FileName.

    Yuri
  • edited September 2020
    2020-09-16-081733

    Yuri --

    Thank you for the guidance.

    I think that the QUICK SAVE setting of PREFIX may be the key for revising the current code rather than replacing it.

    I think I tried having the CODE change the DisplayName but I may have tested that on an image that came from a FILE on DISK.  This may have caused QUICK SAVE so allow the FILE NAME to supersede the DISPLAY NAME.  In the actual usage situation from the user, the IMAGE comes from the CAMERA so QUICK SAVE may respect a DisplayName set by CODE.

    I will dig into this later today.

    Thanks again.

    -- Matt

  • 2020-09-18-152621

    Yuri --

    I worked with the CODE that you suggested that is meant to modify the functionality of the

       QUICK SAVE

    for ANALYSIS and for PUBLICATION.

    For some reason, the QUICK SAVE insists on using the DISPLAY NAME assigned by the CAPTURE MODULE.

    Using code to change the DISPLAY NAME and then calling QUICK SAVE does not work and changing the QUICK SAVE PREFIX does not work.

    The FILES that are created are named using the DISPLAY NAME assigned by the CAPTURE MODULE plus an INDEX if an existing FILE has the same name.

    At this point it looks like the best resolution is to use the two SAVE ROUTINES that you supplied with alterations for them to accept a FILENAME from the CALLING CODE.

    If you would be available to review this via a WEBEX MEETING, that would be super.

    Thanks.

    -- Matt


  • 2020-09-18-163257

    Yuri --

    Here is another mystery for you.

    The CODE section below generates 5 TIF IMAGE FILES.

    The TEST00 section of the code generates an L2 IMAGE that is 14.4 MB.

    The TEST01 section of the code generates an L2 IMAGE that is 12.8 MB.

    The TEST02 section of the code generate an L2 IMAGE that is 12.8 MB.

    It seems that the LZW COMPRESSION does not work less the image has been saved in an uncompressed mode first.

    Poking at this a bit further, I find that TEST03 works in the second set of code.

    It seems that COMPRESSIONS will work but it doesn't work to set it to 2 and go, it works if it is set to 0 (or 1) and then to 2 as shown in the TEST03 example below.

    These tests were done with PREMIER 9.3 3D.  This code is being developed for a customer that has some issues with 10 and cannot upgrade.

    Thanks.

    -- Matt

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

            Dim im0 As McImage=ThisApplication.ActiveImage
            With im0.File
                .Format="TIF"
                .Compression=2 'TIFFCOMP_LZWDiff
                im0.SaveAs _
                    ( _
                    textBox_WorkingFolder.Text & _
                    "\" & _
                    "TEST00" & _
                    ".L2.TIF"
                    )
            End With
    
            Dim im As McImage=ThisApplication.ActiveImage
            With im.File
                .Format="TIF"
                .Compression=0 'No Compression
                im.SaveAs _
                    ( _
                    textBox_WorkingFolder.Text & _
                    "\" & _
                    "TEST01" & _
                    ".L0.TIF"
                    )
                .Compression=1
                im.SaveAs _
                    ( _
                    textBox_WorkingFolder.Text & _
                    "\" & _
                    "TEST01" & _
                    ".L1.TIF"
                    )
                .Compression=2 'TIFFCOMP_LZWDiff
                im.SaveAs _
                    ( _
                    textBox_WorkingFolder.Text & _
                    "\" & _
                    "TEST01" & _
                    ".L2.TIF"
                    )
            End With
    
            Dim im2 As McImage=ThisApplication.ActiveImage
            With im2.File
                .Format="TIF"
                .Compression=2 'TIFFCOMP_LZWDiff
                im2.SaveAs _
                    ( _
                    textBox_WorkingFolder.Text & _
                    "\" & _
                    "TEST02" & _
                    ".L2.TIF"
                    )
            End With
    



            Dim im3 As McImage=ThisApplication.ActiveImage
            With im3.File
                .Format="TIF"
                .Compression=0 'No Compression
    '            im.SaveAs _
    '                ( _
    '                textBox_WorkingFolder.Text & _
    '                "\" & _
    '                "TEST03" & _
    '                ".LX.TIF"
    '                )
                .Compression=1
    '            im.SaveAs _
    '                ( _
    '                textBox_WorkingFolder.Text & _
    '                "\" & _
    '                "TEST03" & _
    '                ".LX.TIF"
    '                )
                .Compression=2 'TIFFCOMP_LZWDiff
                im3.SaveAs _
                    ( _
                    textBox_WorkingFolder.Text & _
                    "\" & _
                    "TEST03" & _
                    ".LX.TIF"
                    )
            End With


  • Hi Matt,

    Regarding QuickSave: FileName has priority for QuickSave. Maybe your captured images are saved on capture, so they have file name already and simply assigning DisplayName will not affect QuickSave.
    A workaround for that is to clear file name, so quick save will use DisplayName:
        Sub SetDisplayName
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            If im.File IsNot Nothing Then
                'reset existing file name
                im.File.FullPathName=""
            End If
            'set display name to be used with QuickSave
            im.DisplayName="MyNameForPublication"
        End Sub
    
    Regarding compression: I tested it in IP 10.0.7 and don't see the problem, the compression is set properly from the first time. If you see this issue in 9.3, then you can use the workaround you've found.

    Best regards,

    Yuri
  • 2020-09-21-111602

    Yuri --

    Thank you for the guidance on a way to manipulate the IMAGE to generate the desired functionality from QUICK SAVE.

    Your post appeared after I elected to use modified versions of the SaveFor Routines that you provided.  My modifications make that CODE create the PATH and FILE NAME based on info in the APP GUI and in the IMAGE DISPLAY NAME set by the CAPTURE DIALOG.

    The APP was delivered yesterday and is now up and running.

    One thing that is not part of this question that may be important to note here is that the DISPLAY NAME for IMAGES within IMAGE-PRO that are opened from DISK will contain the EXTENSION (.TIF, .JPG, etc) depending upon whether the settings of WINDOW EXPLORER.  If the EXPLORER + VIEW + OPTIONS + VIEW has the HIDE OPTION OFF as shown here


    or EXPLORER + VIEW RIBBON + SHOW / HIDE SECTION has the FILE NAME EXTENSIONS OPTION ON as shown here


    then the IMAGE DISPLAY NAME in IMAGE-PRO will also include the EXTENSION.  If these options are in the opposite mode, then IMAGE-PRO will not show the EXTENSION in the DISPLAY NAME.

    This bites me occasionally because my computer is set to display EXTENSIONS and sometimes my CODE is written to expect this situation which is not always (by default is not) true.

    Thanks again

    -- Matt






  • Hi Matt,

    You shouldn't rely on DisplayName to identify the file, but rather use File.FullPathName or File.FileName. You can also strip extension using .NET function System.IO.Path.GetFileNameWithoutExtension(...)

        Public Sub Test2
            Debug.Print (ThisApplication.ActiveImage.DisplayName)
            Debug.Print (ThisApplication.ActiveImage.File.FileName)
            Debug.Print (ThisApplication.ActiveImage.File.FullPathName)
            Debug.Print (System.IO.Path.GetFileNameWithoutExtension(ThisApplication.ActiveImage.File.FullPathName))
        End Sub
    

    Yuri
  • 2020-09-22-114303

    Yuri --

    Thanks for those options.

    I have been using

        ThisApplication.ActiveDocument.FileName

    to get this information.

    Is there an advantage to using the

        ThisApplication.ActiveImage

    properties over the

        ThisApplication.ActiveDocument

    properties?

    Thanks.

    -- Matt

  • Hi Matt,

    Yes, you can use ActiveDocument.FileName, it returns the same name.

    Yuri

  • edited September 2020
     
Sign In or Register to comment.