Home Image-Pro General Discussions
Options

Fetch Data (simple)

Hi,

Again a beginner's question but I had to give up:

Can't get a value for StDevIntIM, what is wrong?


Public Function Convert8bitGrey() As SimpleScript
        Convert8bitGrey = New SimpleScript
        Dim doc1, image1, doc2, StDevIntIM
'....a set of functions before such as conversion, measurement definition etc....
'.
'.

    With Application.DocumentCommands.Active(Convert8bitGrey)
            .Run(doc2)
        End With

        With Measure.MeasurementsCommands.ExecuteCount(Convert8bitGrey)
            .Run(doc2)
        End With

        With Automate.ScriptingCommands.FetchData(Convert8bitGrey)
            .Expression = "<McMMData>.Statistics(eMeasures.RgnStdDevIntensity).Mean"
            If .Run(doc2) Then
                StDevIntIM = doc2.Statistics(eMeasures.RgnStdDevIntensity).Mean
                MsgBox("")&StDevIntIM 'is never displayed

            End If
        End With

        MsgBox("")&StDevIntIM ' this is empty
    End Function

The if .Run(doc2) also not .run() statement or whatever I tried does not work. 
The first Msgbox is never displayed, which means to me that ...FetchData().run does not exist?
How do I get the value into the variable?
Thx Daniel

Best Answer

  • Options
    Answer ✓
    Hi Daniel,

    Here is a macro with the required syntax to count objects and access measurements statistics.

    Pierre

        Public Sub GetStatistics()
            Dim doc1, mdata, stdevInt
            Dim stats As StatsClass
    
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            With Measure.MeasurementsCommands.ExecuteCount(Nothing)
                .Run(doc1)
            End With
    
            With Measure.MeasurementsCommands.GetData(Nothing)
                .Run(doc1, mdata)
            End With
    
            With Automate.ScriptingCommands.FetchData(Nothing)
                .Expression = "<McMMData>.Statistics(eMeasures.RgnStdDevIntensity)"
                If .Run(mdata, stats) Then
                    stats = mdata.Statistics(eMeasures.RgnStdDevIntensity)
                    MsgBox stats.Mean
                End If
            End With
    
        End Sub
    
    

Answers

  • Options
    Hi Daniel,

    The variable should be inside brackets: MsgBox(StDevIntIM).

    Nikita.

  • Options

    That's it.:-)

    For completeness:

    Here the sub solution:

    Public Sub GetVars
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
            Dim StDevIntIM2, MeanIntIM
    
            If md.SubFeatures.Count>0 Then
                Debug.Print "Mean Int = " & md.SubFeatures(0).Value(eMeasures.RgnDensity)
            MeanIntIM = md.SubFeatures(0).Value(eMeasures.RgnDensity)
            StDevIntIM2 = md.SubFeatures(0).Value(eMeasures.RgnStdDevIntensity)
            Debug.Print MeanIntIM
            Debug.Print StDevIntIM2
    
            End If
    
    End Sub

Sign In or Register to comment.