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

Mechanism to loop through currently open images . . .

All --

I'm looking for a bit of code that will loop through the N currently open images once and do something simple like

-- Activate image X of N currently open images
-- Announce the name of image X

I can get the number of open images several ways but I do not see where there is LIST that I can acquire and then loop through.

Thanks.

-- Matt

Best Answers

  • edited September 2013 Answer ✓

    This is the crudest possible macro for it. You may want to do this differently using commands as they would be editable in Design mode.

        Public Sub EnumWins
            Dim win As MediaCy.IQL.Application.McWindow
            For Each win In ThisApplication.Windows
                Debug.Print win.Name
            Next
        End Sub
  • edited September 2013 Answer ✓
    To add to John's answer, you can then activate each window using win.Activate.
    And here is an example usi8ng commands that would be designer friendly.
        Public Function LoopOnDocs() As SimpleScript
            LoopOnDocs = New SimpleScript
            Dim docList1 = New List(1), doc1
    
            With Automate.ScriptingCommands.CodeCommand(LoopOnDocs)
                If .Run() Then
                    ' User Code Here
                    docList1 = ThisApplication.Documents.Values
                End If
            End With
    
            With New Workflow.ForEach(LoopOnDocs)
                .Text = "For Each"
                .Run(docList1, doc1)    ' Designer Support Code
                For Each doc1 In docList1
    
                    With Application.DocumentCommands.Activate(.Me)
                        .Run(doc1, doc1)
                    End With
    
                    With Automate.ScriptingCommands.CodeCommand(.Me)
                        If .Run() Then
                    ' User Code Here
                            MsgBox doc1.Name
                        End If
                    End With
    
                Next
    
            End With
    
        End Function
  • Answer ✓
    Matt,

    This kind of macro runs within the designer to build its graphical representation, this is the reason why the code commands have their code run only when the Run() method returns True, which is the case when the macro runs "for real". So if you add some code to the macro you have to be careful to only put it inside these commands. If you don't care about the designer view, you can also write plain macros (like John's version of the loop) and call commands from there without any limitation as in the following example.

        Public Sub LoopOnDocs2()
            Dim doc As IMcDocument
    
            ThisApplication.Output.Show()
    
            For Each doc In ThisApplication.Documents.Values
                With Application.DocumentCommands.Activate(Nothing)
                    ThisApplication.Output.PrintMessage(doc.DisplayName & " (" & TypeName(doc.Data) & ")")
                    .Run(doc, doc)
                End With
            Next
    
        End Sub
    

    Pierre 

Answers

  • One way is the Application.Windows collection. There could be multiple windows open on a single image, but that will list everything the user sees.

  • John --

    Thank you for the response.

    I've been poking at

        Application.Windows

    but don't have enough info to do what I want.

    I tried using

        GetEnumerator

    since it looked promising but I got errors.

    I don't seem to be able to get a list of NAMES that I could use with

        Application.DocumentCommands.Activate

    I don't seem to be able to get a list of something like the IPP7 (DOCUMENT) IDS either.

    Can you please gin up an example that will point me in the right direction?

    Thanks.

    -- Matt
  • Gentlemen --

    Thank you for your examples.

    I'm sure that I'll be able to get the job done now.

    Thanks again.

    -- Matt
  • Pierre --

    I've implemented the macro code that you provided in a macro for a customer.

    Within the macro, I replaced your

        MsgBox doc1.Name

    with appropriate

        ThisApplication.Output

    commands.

    Because of this, I can see that this macro is running whenIPP9 starts (because the OUTPUT WINDOW opens and contains the dashes and asterisks from

                'Update the output window
                ThisApplication.Output.PrintMessage "-------------"

                'Update the output window
                ThisApplication.Output.PrintMessage "* * * * *"

    commands within the macro.

    If I, close all images, clear the output window, shut down IPP9, and restart IPP9, the output window opens and shows the asterisks and dashes.

    Can you point me to what might be making this macro run at IPP9 STARUP?

    I've not done either of the things described within the FORUM entry titled

        "How to run a macro when Image-Pro Premier starts"

    Thanks.

    -- Matt
  • Pierre --

    Thank you for the additional information and example code on this question.

    I know it helps me to better understand the behavior of IPP9 and I have faith it will help others as well

    Thanks again.

    -- Matt
Sign In or Register to comment.