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
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
0
Answers
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:
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
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:
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.
Henri
You cannot access textbox1 from different file (Module1.vb), you have to pass the value from App1.vb, like this:
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
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
- On Error Resume Next
- TRY CATCH FINALLY
- 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.
- You can also use the DOUBLECLICK EVENT to trigger the CODE that includes the OPENIQO FUNCTION
- 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-- This will handle the ERROR and proceed without causing an issue.
-- This can handle the error and act accordingly
Another way to handle that situation is by using a global variable.
You can define a global variable in Module1.vb:
and set it in the App:
Then use this variable in the macro:
Regards,
Yuri
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
------------------------------------------------------------------------------------
Create 'Browse' button
Display files in combobox:
FolderBrowserDialog1 is an object in Henri's macro, you, probably, don't have it.
You can search internet for a sample how to open File Open dialog in VB.NET and use it in your macro.
Yuri