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

Start Batch Processing automatically when IPP9 starts?

I am intending to use the Batch Processing system to watch a folder and run an analysis on the files that appear there, but I need it to start the batch processing automatically when IPP starts.

Currently when I start IPP9 the correct macro is selected in the "Loop On" box, but I have to set the folder to watch, and the press Start. Can this be automated?

Best Answers

  • Accepted Answer
    Hi Richard,

    This code will start the batch macro to monitor the selected ("C:\OnLoopFolder") folder then Premier loads this project (you can open the Task Manager to see the macro). Then new file detected in the selected folder, then it will be open in the Premier and "OnLoopMacro" macro will be executed.
    Public Module Macros
    
        Private WithEvents _timer As System.Windows.Forms.Timer = Nothing
        Private WithEvents _macro As MediaCy.Addins.Scripting.BatchMacro = Nothing
    
        Public Sub ThisProject_Loading() Handles ThisProject.Loading
            If _timer IsNot Nothing Then
                _timer.Stop
            End If
    
            _timer = New System.Windows.Forms.Timer
            _timer.Interval = 5000
            _timer.Start
        End Sub
    
        Public Sub ThisProject_Unloading() Handles ThisProject.Unloading
            If _timer IsNot Nothing Then
                _timer.Stop
            End If
    
            If _macro IsNot Nothing Then
                _macro.Cancel
            End If
        End Sub
    
        Private Sub _timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _timer.Tick
            _timer.Stop
            _timer = Nothing
    
            If _macro IsNot Nothing Then
                _macro.Cancel
            End If
    
            _macro = New MediaCy.Addins.Scripting.BatchMacro
            _macro.Input.Value = New System.Collections.Generic.List(Of Object)
            _macro.Input.Value.Add("C:\OnLoopFolder")
            _macro.LoopMacroFile = "Project1>Macros.vb"
            _macro.LoopMacroName = "OnLoopMacro"
            _macro.DocumentFormats = "*.png;*.jpg;*.jpe;*.jpeg;*.jp2;*.jpf;*.fits;*.fit;*.fts;*.bmp;*.ipraw;*.dcm;*.dicom;*.mp4;*.mov;*.m4v;*.avi;*.seq;*.tif;*.tiff;*.btf;*.wmv;*.mcs;*.ips;*.deb;*.avz;*.czi;*.dm3;*.dm4;*.dv;*.oib;*.oif;*.ics;*.lei;*.lif;*.lsm;*.nd;*.nd2;*.ndpi;*.ndpr;*.ndpis;*.vms;*.vmu;*.scn;*.stk;*.sws;*.tim;*.txt;*.xml;*.zvi"
            _macro.DisplayDocuments = True
            _macro.CloseDocuments = True
            _macro.MonitorFolders = True
            _macro.Schedule
        End Sub
    
        Private Sub _macro_StatusChanged(ByVal sender As MediaCy.IQL.Application.McCommand, ByVal e As System.EventArgs) Handles _macro.StatusChanged
            If _macro IsNot Nothing Then
                If _macro.Status = McCommand.TaskStatus.IsError Or _macro.Status = McCommand.TaskStatus.IsProcessed Then
                    _macro = Nothing
                End If
            End If
        End Sub
    
        Public Function OnLoopMacro() As SimpleScript
            OnLoopMacro = New SimpleScript
        End Function
    
    End Module
    

    Thanks,
    Nikita.
  • Accepted Answer
    Hi Richard,

    The BatchMacro automatically opens nearly detected image and executes OnLoopMacro. In the OnLoopMacro you can use ActiveImage to get access to the image:
        Public Function OnLoopMacro() As SimpleScript
            OnLoopMacro = New SimpleScript
    
            With Automate.ScriptingCommands.CodeCommand(OnLoopMacro)
                If .Run() Then
                    ' User Code Here
                    Dim im As McImage = ThisApplication.ActiveImage
    
                    If im IsNot Nothing Then
                        Debug.Print(im.DisplayName)
                    End If
                End If
            End With
    
        End Function
    

    Nikita.

Answers

  • Thanks, I will try that today.
  • That works perfectly. Thanks.
  • I might be missing something obvious here, but how does the OnLoopMacro know which file has been detected in the watched folder, and thus needs attention?
    The image doesn't appear to be loaded automatically, and I cannot see any obvious properties that hold a filename by rummaging through the ThisApplication or _macro objects when it is running.
Sign In or Register to comment.