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

Opening files using an array of file names

I've created many (>300) unique ROIs in a single Feature Manager file, each associated with a unique file. I've parsed the file to identify the collection index for each file's ROI.  I have a macro that will process each file, but I'm trying to add the code that will loop through the previously loaded array, to open the file and use the appropriate ROI.  The file name is in Filenm but I get this error:

Value cannot be null. Parameter name: key
[C:\Users\chg0800\Documents\Image-Pro Premier 64-bit\9.3\Scripts\Project1\Project1.ipp>C:\Users\chg0800\Documents\Image-Pro Premier 64-bit\9.3\Scripts\Project1\Macros.vb|processdata#152] .Run(docList1)

(X was Dim'd at the global level (not shown, here):

Public Function processdata() As SimpleScript
        processdata = New SimpleScript
        Dim  image1, doc2, image2, doc3, window1, image3, doc4, window2, window3, window4
        Dim var1 = ThisApplication.Path(mcPathType.mcptProgram) & "Welcome\Welcome.htm", doc5
        Dim Filenm As String
        Dim docList1 = New List(1), doc1

        With Automate.ScriptingCommands.CodeCommand(processdata)
            If .Run() Then
                ' User Code Here
                Call LoadFn()
                X = 1
                Debug.Print X
            End If
        End With

        With Automate.ScriptingCommands.WhileLoop(processdata)
            ' User condition passed to Run(<expression>)
            X = 1
            While .Run(x<295)
                Filenm = Fn(X)&".tif"

        With Application.DocumentCommands.OpenImage(processdata)
            .Filenames = New String() {Filenm}
        End With

        With Application.DocumentCommands.Active(processdata)
        End With

        With [Select].FeaturesManagerCommands.Apply(processdata)
            .Collection = X
            .Feature = -1
            .Item = -1
        End With


  • Hi jcov,

    I'm having similar error message if file is not exist. Please, check "Filenm" variable before "OpenImage" command.

  • I did, and it has the correct, full path and filename...
  • jcov, this is my test macro, please try it:
        Public Function OpenTestImagesInLoop() As SimpleScript
            OpenTestImagesInLoop = New SimpleScript
            Dim i, docList1
            With Automate.Scripting.DefineCommands.IntegerVariable(OpenTestImagesInLoop)
                .Value = 1
            End With
            With Automate.ScriptingCommands.WhileLoop(OpenTestImagesInLoop)
                ' User condition passed to Run(<expression>)
                Dim s As String
                While .Run(i <= 5)
                    s = ThisApplication.Path(mcPathType.mcptWritableImages) & "SPOTS" & i & ".tif"
                    With Application.DocumentCommands.Open(OpenTestImagesInLoop)
                        .Filenames = New String() {s}
                    End With
                End While
            End With
        End Function
    I've created 5 images in ThisApplication.Path(mcPathType.mcptWritableImages) STOPS1.tif,STOPS2.tif, etc. and all 5 images open fine. 

    Could you please paste all macros.


  • 2017-04-24-120356

    JCOV --

    I have not completely digested all of the information above but in similar situations, my solution was to have an ROI FILE (XYZ123.ROI) that is named similar to the IMAGE FILE (XYZ123.TIF) and only contains the ROI INFO for the appropriate IMAGE (XYZ123).

    This can be achieved by clearing the FEATURE MANAGER before SAVING the ROIS in the MANAGER and then in a FILE and by clearing the FEATURE MANAGER before LOADING the ROIS from the FILE.

    I hope this suggestion is helpful.

    -- Matt
  • Nikita,

    I ended up creating a new module to pair down to the relevant macros to share.  I ran the code again, from the new module, and it ran fine!

    I think there was something that got corrupted at some point.

    Bottom line:  The code is running as expected.



  • Matt,

    Thanks.  We were thinking (after the fact) that this would have been more straightforward.  Because of the structure of the Feature Manager file (in the IPP interface) we thought that the individual ROIs would be more addressable in a friendly way.

    We had already loaded 000's of ROIs in the Manager, and were not cherishing the thought of redoing that.  I think our current path will work fine, this time (now that the code is running - see above).



  • 2017-04-24-124326

    Jeff --

    I'm glad your code is up and running.

    I'm also glad that you have an alternate design to consider on your next project.

    -- Matt
Sign In or Register to comment.