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

menu to access public routine and stop macro

Hi,

i'm looking for two things.

1) Is there a way to customize the ribbon, or the quick access toolbar to add a call of some public procedures from my project ?

2) At the beginning of a procedure I need to show popup a message, that will be always visible on the somewhere on the screen while the procedure execution, and from which if the user press "OK" the macro execution will stop. My procedure will show other popups, so this popup must be "non-modal" and it shouldn't block any other popups.

Thanks in advance for your time.

Martin

Answers

  • edited January 2015
    Hi Martin,

    Yes, it is possible.

    1) You can activate "Quick access" property of the macro to add the macro to quick access toolbar. (you can do in tin the properties page of the macro)

    2) It can be done by activating Interactive mode of any command. You can do it by clicking the "Prompt user in imaging workspace" menu item in the context menu of the command over the properties page. You can find more details in this link  http://forums.mediacy.com/discussion/comment/659/#Comment_659 or check "Automate" section of Image-Pro Premier Online help.

    Regards,

    Yuri

  • Hi Yuri.

    Question 1), thanks, it works great.

    Question 2), can you help further with that one please ?

    I found a command "Automate.ScriptingCommandes.Interaction".
    I found the command to "pause" the macro.

    But I'm not sure how to integrate all of this to do what I need.

    Here's my main Sub of my macro.
        Public Sub AnalyseImage_0305
            m_strWorkBookPath = Path.Combine(m_strWorkBookRootPath, "AnalyseImage_03-5.xls")
    
            With Automate.ScriptingCommands.Interaction(Nothing)
                .Prompt = "Arrêter la macro - cliquer OK"
                .Interactive = True
                .Run(ThisApplication)
            End With
    
            AnalyseImageMain()
    
            Automate.ScriptingCommands.PauseMacro(Nothing).Run(ThisApplication.ActiveDocument)
        End Sub
    
    What I need to do is to :
    
    1) Show an interactive message to give the user the ability to press ok to stop the macro
    2) Execute my routine "AnalyseImageMain()"
    3) If the user press "OK" on message in step 1), run the command to pausemacro.
    4) If the user never press "OK" on message and the routine "AnalyseImageMain()", close the message.
    Can you help me again ? Thanks, Martin
  • Hi Martin,

    I don't quite understand your workflow. It looks like you want to have a combination of modal and mod-less prompts. Mod-less prompts show an interaction prompt (balloon) and allow user to do some interactive operations, the programs stays on that macro command untill user clicks Ok or Cancel.

    There is also a possibility to show modal dialog with explicit Yes/No questions.(user cannot do anything else).

    You should try to arrange your workflow using the given possibilities.

    Yuri
  • Hi Yuri,

    well, maybe I should re-words what my automation do.

    My script is looping all images in a specific folder.

    For each image I do these steps :
    - Open image
    - Apply spacial calibration read from an excel file
    - Ask user to draw one kind of measure
    - Ask user to draw an other kind of measure
    - Ask user to draw an other kind of measure
    - Save trace data
    - Export measurements information to Excel
    - Close image

    Here's what i'm using to prompt the user to draw an object :
            With Measure.MeasurementsCommands.Add(m_SimpleScript)
                .Prompt = "Veuillez tracer"
                .MeasurementType = McMeasurements.enumMMSTypes.mmtsPolygon
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
                .FeatureName = MeasureType
                .SnapFeature = False
                .Interactive = True
                .Run(image1, meas1)
            End With
    
    As there may be a lot of images to loop, I need to give the user the ability tocompletely stop the macro (same behavior than click on "End" in project workbench.
    
    My main routine is named AnalyseImage_0305. This routine obviously call a lot of other functions.
    I tried using a form ; I created a form with 2 buttons, the first one to call my routine AnalyseImage_0305, and the second to stop all execution.
    I thought that because the form is always shown, I would be able to do what I want, but I didn't found something to stop everything. Here's the last thing I tried but it didn't work... Dim m_RunMacro As SimpleScript
        Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click
            m_RunMacro = New SimpleScript
    
            With Automate.ScriptingCommands.PlayMacro(m_RunMacro)
                .MacroFile = "AnalyseImage>Macros.vb"
                .MacroName = "AnalyseImage_0305"
                .Run(Nothing)
            End With
    
        End Sub
    
        Private Sub button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button2.Click
            m_RunMacro.Cancel
            m_RunMacro.Dispose
    
            Form.Close
        End Sub
    Is it more clear ? Can you give me a hint ? Thanks, Martin
  • edited January 2015
    Hi Martin,

    Now I understand what you want, you just want to break the processing loop if it takes too long.

    There are 3 different solutions proposed in this comment:  http://forums.mediacy.com/discussion/comment/548/#Comment_548 

    It will work for you too, though there the macro doesn't show any prompts.

    If you show a prompt (balloon), it has 2 buttons Ok and Cancel. You can use Cancel to stop the loop.
    Below is the macro that demonstrates it. You put the interactive command into try/catch block and exit the macro from Catch, which is called when user clicks Cancel:

            Try
                With Measure.MeasurementsCommands.Add(NewMacro)
                    .MeasurementType = McMeasurements.enumMMSTypes.mmtsLine
                    .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
                    .Points.Add(New System.Drawing.PointF(105.4366F,44.28336F))
                    .Points.Add(New System.Drawing.PointF(182.4053F,80.1318F))
                    .FeatureName = "L1"
                    .SnapFeature = False
                    .Interactive=True
                    .Run(image1, meas1)
                End With
            Catch
                MsgBox "User clicked Cancel"
                Exit All 'exit the loop
            Finally
            End Try
    


    Regards,

    Yuri
  • Hi Yuri,

    cool, I have an option, thanks !

    I allow myself to ask you another way to stop everything.

    My macro shows prompt (balloon) to tell user what he needs to draw.

    I would like to use the form I tried in my tests, my form with 2 buttons (Run and Stop).

    On the click of "Run", my macro start to loop all images and prompt user (balloon) to draw different object, and etc. etc.
    Yes, now, I will add the Try Catch to stop everything, at this point, if the user click cancel but I would like, if the user click on "Stop" button on the form, to "Exit all"... stop everything ... and obviously, at this moment, the chance that a prompt is shown is high.

    I took a look of the other thread that you post me and I don't think it's suitable for my case.

    Is it possible to do something like I want ?

    Thanks,

    Martin
  • Hi Martin,

    There's actually a way to stop the current interaction but it's a bit more involved. Here is the code, I am also attaching the project.
    
        Private Sub btnRun_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnRun.Click
            Try
                InteractiveMacro()
            Catch
                ' Macro cancelled
            Finally
            End Try
        End Sub
    
        Private Sub btnStop_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnStop.Click
            If Interaction.ThisInteraction.DialogResult=System.Windows.Forms.DialogResult.None Then
                Interaction.ThisInteraction.Close()
                ' This will stop the interaction and stop the InteractiveMacro
                Interaction.ThisInteraction.DialogResult=System.Windows.Forms.DialogResult.Cancel
                ' This would stop the interaction and continue the InteractiveMacro
                'Interaction.ThisInteraction.DialogResult=System.Windows.Forms.DialogResult.OK
            Else
                Automate.ScriptingCommands.PauseMacro(Nothing).Run()
            End If
        End Sub
    

    Pierre


  • And here is the project package.

    PIerre
  • Many thanks Pierre.

    I'll give a try as soon as I get back to home.

    Regards,
Sign In or Register to comment.