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

Programmatically extracting data from the data collector

I am building an application in which I am capturing data from an image document grabbing count/size data and stats. I now would like to use the data collector in an effort to collect data from replicate images accessing summary stats as I measure images. I need to know how to programmatically access stat data from the data collector. Also I would like to access all or individual blocks of data from the data collector. Could you forward example code? 

Best Answer

  • edited October 2013 Answer ✓
    Rod,

    Yes, you are right GetData command will be available only in 9.1. Meanwhile you have to get that DataSet using direct property, like this:

       Public Function GetDCStats() As SimpleScript
            GetDCStats = New SimpleScript
            Dim dataSet
    
            With Automate.ScriptingCommands.CodeCommand(GetDCStats)
                If .Run() Then
                    ' User Code Here'
                    'get Data
                    dataSet=MediaCy.Addins.DataCollector.McDataCollectorAddin.ThisAddin.Document.Data
                    For Each table As System.Data.DataTable In dataSet.tables
                        Debug.Print String.Format("Table - {0}",table.TableName)
                        For Each col As System.Data.DataColumn In table.Columns
                            'print Mean'
                            Debug.Print String.Format("Mean of {0} = {1}", col.Caption,GetColumnStats(col).Mean)
                        Next
                    Next
                End If
            End With
        End Function
    

    Yuri

Answers

  • Hello Rod,

    I suggest that you take a look at the command DataCollectorGetDataCommand, it returns a System.Data.DataSet so you have access to the entire pool of data using a standard .NET object. We will get back to you with more details about statistics but here is a short example.

        Public Function Macro1() As SimpleScript
            Macro1 = New SimpleScript
            Dim dataSet
    
            With Measure.Data.CollectorCommands.GetData(Macro1)
                .Run(dataSet)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(Macro1)
                If .Run() Then
                    ' User Code Here
                    Dim table As System.Data.DataTable
                    For Each table In dataSet.tables
                        Debug.Print table.TableName
                    Next
                End If
            End With
    
        End Function

    Pierre

  • edited October 2013
    Hi Rod,

    If you want to export Data Collector stats somewhere, you can use recordable commands, like this:
            With Measure.Data.Collector.TableCommands.CopyToClipboard(Nothing)
                .UseStatistics = True
                .Run()
            End With
    
    If you need to use Data Collector's statistics in the macro, then you can get it from the column data using McBasicStatistics class 

     Example:

        Public Function GetDCStats() As SimpleScript
            GetDCStats = New SimpleScript
            Dim dataSet
    
            With Measure.Data.CollectorCommands.GetData(GetDCStats)
                .Run(dataSet)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(GetDCStats)
                If .Run() Then
                    ' User Code Here'
                    For Each table As System.Data.DataTable In dataSet.tables
                        Debug.Print String.Format("Table - {0}",table.TableName)
                        For Each col As System.Data.DataColumn In table.Columns
                            'print Mean'
                            Debug.Print String.Format("Mean of {0} = {1}", col.Caption,GetColumnStats(col).Mean)
                        Next
                    Next
                End If
            End With
        End Function
    
        'Returns complete stats of the column.'
        Public Function GetColumnStats(col As System.Data.DataColumn) As MediaCy.IQL.ObjectManager.BASIC_STATISTICS
            Dim rows As New System.Collections.Generic.List(Of Double)
            With ThisApplication.Engine.McObjects.GlobalTools
                For Each row As System.Data.DataRow In col.Table.Rows
                    Dim v As Object = row(col)
                    If IsDBNull(v) OrElse Not IsNumeric(v) Then
                        rows.Add(.McMissingDouble)
                    Else
                        rows.Add(v)
                    End If
                Next
                Return .McBasicStatistics(rows.ToArray()) 'return stats'
            End With
        End Function
    
    GetColumnStats function returns complete statistics for the given column, so you can use any of the statistical fields (check macro help on MediaCy.IQL.ObjectManager.BASIC_STATISTICS for more info).

    Yuri

  • Yuri:

     

    Thank you very much for the example. This is most helpful. However, I am running 9.0.4 and at Load, the Scripting Workbench reports that it cannot find GetData as a member of MediaCy.Automation.Measure.Data.CollectorCommands. I checked the Help file and GetData is not listed there. I am overlooking something obvious I am sure. Can you point me in the correct direction?

    Thanks much!

     

    //////Rod

  • Yuri:

    Thanks much. Do you know when 9.1 will be released?

    ////Rod

Sign In or Register to comment.