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

Determining whether an image is calibrated or not . . .

All --

I'm writing application and am now up to IPP904.

If there is SPATIAL CALIBRATION on the ACTIVE IMAGE, the following returns the UNITS ABBREVIATION for the SPATIAL CALIBRATION
        'Learn the abbreviation for the active calibration unit
        Dim MySpatialCalibrationUnitAbbrev As String
        MySpatialCalibrationUnitAbbrev = ThisApplication.ActiveImage.SpatialCalibration.UnitAbbrev
If there is not a SPATIAL CALIBRATION on the ACTIVE IMAGE, the previous code returns the following ERROR

    "ActiveX Automation: Object var is 'Nothing'."

via

        'Set up error handling
        On Error GoTo MyHandler

        'Learn the abbreviation for the active calibration unit
        Dim MySpatialCalibrationUnitAbbrev As String
        MySpatialCalibrationUnitAbbrev = ThisApplication.ActiveImage.SpatialCalibration.UnitAbbrev

MyHandler:
        Debug.Print Error
I've looked at all of the options behind

    ThisApplication
.ActiveImage.SpatialCalibration.

and everything I've tried seems to generate an error if the image is not calibrated.

I can build upon this error handling concept to have the program handle the NOT CALIBRATED situation but my question is . . . .

Is there a more graceful way to handle sensing whether an image is calibrated?

Thanks.

-- Matt

Best Answer

  • Accepted Answer
    The correct syntax would be:

        Sub PrintCalibration
            If ThisApplication.ActiveImage.SpatialCalibration IsNot Nothing Then
                Debug.Print ThisApplication.ActiveImage.SpatialCalibration.UnitAbbrev
            End If
        End Sub
    

Answers

  • Pierre --

    Thank you for your example.

    I've changed my code to:
            'Declare variables used within the if statement
            Dim MySpatialCalibrationUnitAbbrev As String
            Dim MySpatialCalibrationPixelSizeX As Single
            Dim MySpatialCalibrationPixelSizeY As Single
    
            'If the imaage has a spatial calibration
             If ThisApplication.ActiveImage.SpatialCalibration IsNot Nothing Then
    
                'Then learn the spatial calibration information
    
                    'Learn the abbreviation for the active spatial calibration
                    MySpatialCalibrationUnitAbbrev = ThisApplication.ActiveImage.SpatialCalibration.UnitAbbrev
    
                    'Learn the pixel size x for the active spatial calibration
                    MySpatialCalibrationPixelSizeX = ThisApplication.ActiveImage.SpatialCalibration.PixelSizeX
    
                    'Learn the pixel size y for the active spatial calibration
                    MySpatialCalibrationPixelSizeY = ThisApplication.ActiveImage.SpatialCalibration.PixelSizeY
    
                Else 'simulate the spatial calibration information
    
                    'Set the abbreviation for the spatial calibration
                    MySpatialCalibrationUnitAbbrev = "pix"
    
                    'Set the pixel size x for the spatial calibration
                    MySpatialCalibrationPixelSizeX = 1.0
    
                    'Set the pixel size y for the spatial calibration
                    MySpatialCalibrationPixelSizeY = 1.0
    
                End If

    Thanks again.

    -- Matt
  • Oops . . . The EDITOR and I ended up with the THANKS AGAIN as part of the CODE and not part of the MESSAGE!!!

    -- Matt
Sign In or Register to comment.