GetSelectedRotatedRectFromViewer Method

NI Vision for Visual Basic

GetSelectedRotatedRectFromViewer Method

Syntax

CWMachineVision.GetSelectedRotatedRectFromViewer Viewer, RotatedRectangle [, RaiseErrorOnBadIndex = True] [, Index = 1]

Return Type

Long

On success, this method returns 0. On failure, this function returns a negative number.

Purpose

Returns a copy of the rotated rectangle at the specified index from the region of interest on the viewer.

Remarks

If another type of shape is at the specified index, this method raises an error. If the index is invalid, this method raises an error only if RaiseErrorOnBadIndex is True. Otherwise, it returns a rotated rectangle the size of the image. This behavior is useful for routines that take optional search rectangles.

Parameters

Viewer As CWIMAQViewer

The viewer that contains the region of interest from which you want to get the rectangle.

RotatedRectangle As CWIMAQRotatedRectangle

On return, this parameter contains a copy of the rotated rectangle that is selected on the viewer. If a rectangle is selected, it is converted into a rotated rectangle and then copied into this parameter.

RaiseErrorOnBadIndex As Variant

[Optional] Indicates whether an error should be raised if index is invalid. If this is set to False, the rectangle returned is the size of the viewer image.

This parameter has a default value of True.

Index As Variant

[Optional] The index of the Region in the CWIMAQViewer.Regions collection. Set this parameter to the appropriate index when the viewer contains multiple regions of interest.

This parameter has a default value of 1.

Example

Private Sub Run_Click()
    'Input objects
    Dim SearchRectangle As New CWIMAQRotatedRectangle
    Dim Options As New CWMVCountAndMeasureObjectsOptions
    Dim Transformation As New CWMVCoordinateTransformation
    
    'Output objects
    Dim ObjectsReport As New CWMVObjectsReport
    
    'Get the currently selected rectangle or rotated rectangle from the viewer. If nothing is
    'selected, get a rectangle representing the entire image.
    CWMachineVision1.GetSelectedRotatedRectFromViewer CWIMAQViewer1, SearchRectangle, False
                                                           
    ' Find objects on the Viewer image in the selected rectangle
    CWMachineVision1.CountAndMeasureObjects CWIMAQViewer1.Image, ObjectsReport, _
                                            SearchRectangle, Options, Transformation
End Sub

See Also

SetupViewerForRotatedRectSelection

CWIMAQViewer.Regions

CWIMAQRegion.Shape

CountAndMeasureObjects