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

Changing the active image

In my app each processing step processes the current image. But now I want to go back to a previous image, how should I do it? I can see the 'active image' button but how do I tell it which image in the processing sequence to make active?

Best Answers

  • edited June 2016 Answer ✓
    Paul --

    There are several ways to accomplish the task that you are asking about.

    I have created and posted some code that should give you an example of the way to use the DISPLAY NAME of the IMAGE to ACTIVATE the IMAGE.  Here is a SCREEN CAPTURE of PREMIER showing the IMAGES and the PROJECT EXPLORER.



    The CODE is below.

    My A.TIF and B.TIF images are attached to this comment.

    Put the A.TIF and B.TIF images into the same FOLDER / DIR as your macro and you can run the OPEN ROUTINES without changing anything.

    I hope this information is helpful.

    -- Matt

    2016-06-07-111757:
    I don't think the FORUM wanted to post my A.TIF and B.TIF images so I have attached them as A.JPG and B.JPG.  They will need to be resaved as TIF FILES or the ".TIF"s in the program will need to be changed to ".JPG"s. -- MMB

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
    Public Module Module1
    
        'Declare PROGRAM VARIABLES
        Dim Prog_VarA
        Dim Prog_VarB
    
        'Subroutine to learn the name of IMAGE A
        Public Sub Learn_Image_A()
    
            'Set PROGRAM variable to name of current image
            Prog_VarA = ThisApplication.ActiveDocument.DisplayName
    
            'Make announcement to user
            MsgBox "I will remember '" & Prog_VarA & "' as IMAGE A."
    
        End Sub
    
        Public Function Open_Image_A()
    
            'Declare LOCAL VARIABLES
            Dim docList1 = New List(1), doc1
    
            'Open the A.TIF that is in the same folder as this macro
            With Application.DocumentCommands.Open(Nothing)
                .Filenames = New String() {MacroDir & "\A.tif"}
                .Run(docList1)
            End With
    
            'Activate the A.TIF image
            With Application.DocumentCommands.Activate(Nothing)
                .Run(docList1(0), doc1)
            End With
    
            'Set PROGRAM variable to name of current image
            Prog_VarA = ThisApplication.ActiveDocument.DisplayName
    
        End Function
    
        'Subroutine to learn the name of IMAGE A
        Public Sub Learn_Image_B()
    
            'Set PROGRAM variable to name of current image
            Prog_VarB = ThisApplication.ActiveDocument.DisplayName
    
            'Make announcement to user
            MsgBox "I will remember '" & Prog_VarB & "' as IMAGE B."
    
        End Sub
    
        Public Function Open_Image_B()
    
            'Declare LOCAL VARIABLES
            Dim docList1 = New List(1), doc1
    
            'Open the B.TIF that is in the same folder as this macro
            With Application.DocumentCommands.Open(Nothing)
                .Filenames = New String() {MacroDir & "\B.tif"}
                .Run(docList1)
            End With
    
            'Activate the B.TIF image
            With Application.DocumentCommands.Activate(Nothing)
                .Run(docList1(0), doc1)
            End With
    
            'Set PROGRAM variable to name of current image
            Prog_VarB = ThisApplication.ActiveDocument.DisplayName
    
        End Function
    
        'Subroutine to active the appropriate IMAGE (A or B)
        Public Function Activate_Image_X()
    
            'Declare LOCAL VARIABLES
            Dim MyRet As String
            Dim MyDocX
    
            'Prompt the user for the appropriate information
            MyRet = InputBox("Please enter the letter for the image you want to activate (A or B).","'Activate_Image_X' asks . . . ","A")
    
            'Branch based on the user information
            Select Case UCase(MyRet)
    
                Case "A"
    
                    Try
    
                            'Activate IMAGE A
                            With Application.DocumentCommands.Activate(Nothing)
                                .Run(Prog_VarA, MyDocX)
                            End With
    
                        Catch
    
                            'Handle an error
                            MsgBox ("Please OPEN or LEARN 'IMAGE A' first!",vbOkOnly,"'Activate_Image_X' asks . . . ")
    
                        Finally
                        End Try
    
                Case "B"
    
                    Try
    
                            'Activate IMAGE B
                            With Application.DocumentCommands.Activate(Nothing)
                                .Run(Prog_VarB, MyDocX)
                            End With
    
                        Catch
    
                            'Handle an error
                            MsgBox ("Please OPEN or LEARN 'IMAGE B' first!",vbOkOnly,"'Activate_Image_X' asks . . . ")
    
                        Finally
                        End Try
    
                Case Else
    
                    'Let the user know that their answer could not be used
                    MsgBox ("You entered something I did not understand",vbOkOnly,"'Activate_Image_X' asks . . . ")
    
                End Select
    
        End Function
    
    End Module
    


  • Answer ✓
    Thanks for your help - I'll give it a try.

Answers

  • Paul --

    You are welcome.

    Good luck.

    -- Matt
  • Hi Paul,

    I can recommend you to activate recording and do all the steps of your workflow. Then you can check the macro and see how multiple images are handled.
    Every command that creates a new image (load, mask, crop,...) returns a pointer to the created document  (doc1, doc2, ...) which can be used in other commands as input.
    There are other collections ThisApplication.Images, Windows, Documents that can be accessed directly by index or name, but it require some low level programming.

    Regards,

    Yuri
Sign In or Register to comment.