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

get the name of the open files

Hi,

I need to get the names of the opened images ( not only the active one) so I can use them as variable to activate the different opened images when needed.

Thank you


 

Best Answer

  • Answer ✓
    It looks like in your macro you activate different image (doc3), which is not the results of the operations in the macro nor the original image, that's why it's identified by name.
    You should come up with a workflow where you either start from a single image or use all it's derivatives, or, if it's not possible, record a macro when you Load images from disk and do further processing. Then you can just make the Open command interactive (set .FileNames = Nothing) and the rest will be the same.

    Yuri

Answers

  • edited March 2017
    You don't really need image name to activate every window, you can use collection of Premier windows ThisApplication.Windows and activate any window in it by wnd.Activate.

    Here is the example:

        Public Sub ActivateWindowsOneByOne
            'use list of windows
            For Each wnd As McWindow In ThisApplication.Windows
                'print window, document, image parameters
                Dim doc As IMcDocument=wnd.Document
                Dim im As McImage=TryCast(wnd.Document.Data,McImage)
                Debug.Print String.Format("Window name = {0}, File name = {1}",wnd.Name,doc.FileName)
    
                wnd.Activate'activate this window, it sets ThisApplication.ActiveImage,ThisApplication.ActiveDocument,ThisApplication.ActiveWindow
                'do something with this window
    
                MsgBox (String.Format("Window {0} activated",wnd.Caption),vbInformation)
            Next
        End Sub
    
    
    If you just want to write a macro that does multi-image processing, which starts from a single image (e.g. you extract channel, create mask, apply filter, do arithmetic operation between these images,...) then you should just activate macro recording and do your steps, all operations and activations will be recorded properly (without names), so you can then run the macro on any other image. 


    Yuri
  • YuriG said:
    You don't really need image name to activate every window, you can use collection of Premier windows ThisApplication.Windows and activate any window in it by wnd.Activate.

    Here is the example:

        Public Sub ActivateWindowsOneByOne
            'use list of windows
            For Each wnd As McWindow In ThisApplication.Windows
                'print window, document, image parameters
                Dim doc As IMcDocument=wnd.Document
                Dim im As McImage=TryCast(wnd.Document.Data,McImage)
                Debug.Print String.Format("Window name = {0}, File name = {1}",wnd.Name,doc.FileName)
    
                wnd.Activate'activate this window, it sets ThisApplication.ActiveImage,ThisApplication.ActiveDocument,ThisApplication.ActiveWindow
                'do something with this window
    
                MsgBox (String.Format("Window {0} activated",wnd.Caption),vbInformation)
            Next
        End Sub
    
    
    If you just want to write a macro that does multi-image processing, which starts from a single image (e.g. you extract channel, create mask, apply filter, do arithmetic operation between these images,...) then you should just activate macro recording and do your steps, all operations and activations will be recorded properly (without names), so you can then run the macro on any other image. 


    Yuri

    Thank you. I started by recording a macro. But in the code of the macro, it actually put the full name of one of the file:

    Public Function Test() As SimpleScript
            Test = New SimpleScript
            Dim doc1, image1, doc2
            Dim var1 = "jet1_25nmGFP170307_001_TIF", doc3, image2, doc4
    
            With Application.DocumentCommands.Active(Test)
                .Run(doc1)
            End With
    
            With Adjust.ImageCommands.Convert(Test)
                .Destination = Image.ConvertTypes.Mono16
                .ConvertOption = Image.ConvertOptions.Scale
                .Visible = True
                .Run(doc1, image1)
            End With
    
            With Application.DocumentCommands.Activate(Test)
                .Run(image1, doc2)
            End With
    
            With Application.DocumentCommands.Activate(Test)
                .Run(var1, doc3)
            End With
    
            With Adjust.ImageCommands.Convert(Test)
                .Destination = Image.ConvertTypes.Mono16
                .ConvertOption = Image.ConvertOptions.Scale
                .Visible = True
                .Run(doc3, image2)
            End With
    
            With Application.DocumentCommands.Activate(Test)
                .Run(image2, doc4)
            End With
    
        End Function


Sign In or Register to comment.