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

Variable user input for App

Dear Forum,

I am trying to create an App that automates cell counts and classifications. The loop macro in my App currently always looks for a specific .iqo and .lcl file for segmentation and classification, which have to be overwritten for different cell types and only allow to store one setting at a time. However, I'd like to allow users to put their specific .iqo and .lcl file name into the app, and the loop subsequently uses this for all images. This way many setting files can be saved and accessed.
I presume there is a way of telling the macro to look for a user input within the app. For example, the user can write 'example.iqo' in a text box and the macro looks for that file within the software's folders. Or maybe there could be a dropdown menu for all available files in a folder. I've not used variables in Image-Pro so any guides or helping documents would be very useful.

Thank you!
Henri

Answers

  • edited March 31
    Hi Henri,

    Yes, it is possible to create an app dialog with multiple input controls, which could be used to define data for your macro. There are many apps on our app center that can be used as examples.
    I've attached a simple app that shows how to pass context of Text boxes to the macro.

    The app uses the following code to pass the data from text boxes and numericUpDown controls to macro:
        Private Sub button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button2.Click
            CollectData(textBox1.text,textBox2.text,numericUpDown1.Value)
        End Sub
    
    The same way you can pass IQO file name or other parameters.
    You can pass the data as function parameters or using global variables.

    You can check the code of more complex apps to see how to implement file browsing or folder selection:
    https://www.mediacy.com/support/imagepro/appcenter/parent-child-analysis-application-detail
    https://www.mediacy.com/support/imagepro/appcenter/wound-healing-application-detail 

    Yuri
  • Thanks for the help so far, Yuri. I'm still a bit stuck unfortunately.

    Regarding the text box input, I've created an app with only 1 text box and a script that should open an .isg file, which is determined by the textbox.


    This is the UI from the App (1 text box and a button to start my script:
    Private Sub textBox1_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles textBox1.TextChanged
        End Sub
    
        Public Sub button2_Click(sender As Object, e As System.EventArgs) Handles button2.Click
            openiqo()
        End Sub



    This is the script to open my .isg file. I've tried using (textBox1.text) as the input from the text box, but I'm pretty sure the syntax is wrong.
    Public Function openiqo() As SimpleScript
            openiqo = New SimpleScript
            Dim image1
    
            With Application.DocumentCommands.ActiveImage(openiqo)
                .Run(image1)
            End With
    
            With Measure.SmartSegmentation.RecipeCommands.Open(openiqo)
                .FileName = ThisApplication.Path(mcPathType.mcptConfigurationFiles) & (textBox1.text)
                .FilterIndex = 1
                .Settings = Nothing
                .FilterInput = True
                .Run(image1)
            End With
    
        End Function



    Henri
  • Hi Henri,

    You cannot access textbox1 from different file (Module1.vb), you have to pass the value from App1.vb, like this:

    Public Sub button2_Click(sender As Object, e As System.EventArgs) Handles button2.Click
            openiqo(texbox1.text)
        End Sub

    and modify the macro adding an input parameter

    Public Function openiqo(filename as string) As SimpleScript
            openiqo = New SimpleScript
            Dim image1
    
            With Application.DocumentCommands.ActiveImage(openiqo)
                .Run(image1)
            End With
    
            With Measure.SmartSegmentation.RecipeCommands.Open(openiqo)
                .FileName = ThisApplication.Path(mcPathType.mcptConfigurationFiles) & (filename)
                .FilterIndex = 1
                .Settings = Nothing
                .FilterInput = True
                .Run(image1)
            End With
    
        End Function

    Yuri
  • Hi Yuri, 


    Thanks, this works well! Just trying to simplify this further, would it be possible to automatically read the content of the text box and run the script (if it exists)?

    Every time I type in the text box, I get an error until I have the full name of the file (which makes sense). Is there a way to say 'ignore error until filename exists' or 'only run openiqo after pressing enter in textbox'?
       Public Sub textBox1_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles textBox1.TextChanged
    
    openiqo(textbox1.text)
    
        End Sub
    
    
    
    Thanks
    Henri
  • 2020-03-31-112302

    Henri --

    I think there are multiple ways to handle the issue that your last question references.
    1. On Error Resume Next
      -- This will handle the ERROR and proceed without causing an issue.
    2. TRY CATCH FINALLY
      -- This can handle the error and act accordingly
    3. Create a BUTTON for the OPENIQO STATEMENT and use the TEXTCHANGED STATEMENT to color code the textbox GREEN if the IQO FILE EXISTS or YELLOW if it does not.
    4. You can also use the DOUBLECLICK EVENT to trigger the CODE that includes the OPENIQO FUNCTION
    5. You can INVENTORY the IQO FILES and put a list of IQO FILES in a DROP DOWN BOX so your user does not have to type (and maybe typo) the name of an IQO FILE.
    I hope this information is helpful

    -- Matt
  • Hi Henri,

    Another way to handle that situation is by using a global variable. 
    You can define a global variable in Module1.vb:

    Public Module Module1
    
        Public IQOFileName As String
    
    

    and set it in the App:
    Public Sub textBox1_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles textBox1.TextChanged
           Module1.IQOFileName=textbox1.text
    End Sub
    Then use this variable in the macro:
    Public Function openiqo() As SimpleScript
            openiqo = New SimpleScript
            Dim image1
    
            With Application.DocumentCommands.ActiveImage(openiqo)
                .Run(image1)
            End With
    
            With Measure.SmartSegmentation.RecipeCommands.Open(openiqo)
                .FileName = ThisApplication.Path(mcPathType.mcptConfigurationFiles) & (IQOFileName)
    .FilterIndex = 1 .Settings = Nothing .FilterInput = True .Run(image1) End With End Function
    Regards,

    Yuri

  • Thanks Yuri and Matt! (Sorry for the late reply!)
    I can't stress enough how much your input has helped me understand the software more.

    I've tried      On Error Resume Next     and  TRY CATCH FINALLY , but was still getting error messages when typing.

    In the end, I went with Yuri's method and modified it slightly. I used an openFileDialog to display all .isg files within that folder in a ComboBox.. Lastly, the macro opens the .isg file that was chosen in the combobox.

    I'll put parts of the code below, in the hopes this would be useful for someone in the future.

    Thank you,
    Henri




    ------------------------------------------------------------------------------------
    'Public variable: Directory for config files
    Public myIsgDir As String
    'Chosen config .isg file
    Public myIsgFile As String

    Create 'Browse' button 
     Private Sub button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button3.Click
    
      FolderBrowserDialog1.ShowDialog()
          Module1.myIsgDir = FolderBrowserDialog1.SelectedPath
          
    
    ComboBox1.Items.Clear
    
    For Each file As String In System.IO.Directory.GetFiles(Dir, "*.isg")
    ComboBox1.Items.Add(System.IO.Path.GetFileName(file))
    
    Next
    
        End Sub

    Display files in combobox:
    Private Sub comboBox1_SelectedIndexChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles comboBox1.SelectedIndexChanged 
    
    Module1.myIsgFile=combobox1.text
    
    
        End Sub
    
    
    
    
    In Macro:
    With Measure.SmartSegmentation.RecipeCommands.Open(NewMacro3)
                .FileName = Module1.myIsgDir & "\" & Module1.myIsgFile
                .FilterIndex = 1
                .Settings = Nothing
                .FilterInput = True
                .Run(doc1)
            End With
Sign In or Register to comment.