Home Image-Pro General Discussions

Graceful way to prompt user for a RECTANGULAR ROI

All --

I have a need for a user to create a RECTANGULAR ROI within IPP9.1.

I have some code which seems to work sometimes but fails to work other times.

When it works, PREMIER activates the RECTANGULAR ROI TOOL and then presents a PROMPT.

When it fails, PREMIER does not activate the RECTANGULAR TOOL but presents the PROMPT (and the user has to activate the TOOL manually).

My code is below.

Can someone point out what I've done wrong please?

Thanks.

-- Matt

    Public Function Demo_Select_Sample_Area()

        'Learn the docid for the current image
        Dim doc1
        With Application.DocumentCommands.Active(Demo_Select_Sample_Area)
            .Run(doc1)
        End With

        'Delete all existing rois
        With Select.RoiCommands.DeleteAll(Demo_Select_Sample_Area)
            .Run(doc1)
        End With

        With Select.RoiCommands.Add(Demo_Select_Sample_Area)
            .Features = Features.Features.ROIs
            .FeatureType = Features.FeatureTypes.Rectangle
            '.Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
            '.Points.Add(New System.Drawing.PointF(rLeft, rTop))
            '.Points.Add(New System.Drawing.PointF(rRight, rBottom))
            '.Angle = 0R
            '.Roundness = New System.Drawing.PointF(0F,0F)
            .ROIType = Features.ROI.ROITypes.Rectangle
            .Prompt = "Please create a RECTANGULAR ROI around the SAMPLE AREA then press OK!"
            .Interactive = True
            .Run(doc1)
        End With

    End Function


Best Answer

  • Answer ✓
    Matt,

    You need an import of MediaCy.Commands and a reference to MediaCy.Commands.Overlays.

    Pierre

Answers

  • P.S.  . . .

    I would also like a "graceful" way to make sure that the MULTIPLE ROI OPTION is OFF.

    The only mechanism that I have gotten to seems to only be able to TOGGLE this OPTION but not set it to ON or OFF.  That would be OK but I've not seen a mechanism to "see" whether it is ON or OFF (to know whether it needs to be TOGGLED).

    Thanks.

    -- Matt



  • Matt,

    Here is a quick macro to do all that. I am using the Interaction command (from the toolbox) at the end of the macro to do the prompt.

    Pierre

        Public Function SelectRoi() As SimpleScript
            SelectRoi = New SimpleScript
            Dim doc1
    
            With Application.DocumentCommands.Active(SelectRoi)
                .Run(doc1)
            End With
    
            With Select.RoiCommands.MultipleROIs(SelectRoi)
                .Text = "Multiple ROIs"
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Unchecked
                .Run(doc1)
            End With
    
            With Select.Roi.ToolsCommands.Rectangle(SelectRoi)
                .Image = .GetImage("Select.Roi.Tools.Rectangle")
                .Overlay = Overlays.OverlayType.ROIOverlay
                .Tool = Overlays.OverlayToolType.McGraphObjRect
                .Run(doc1)
            End With
    
            With Automate.ScriptingCommands.Interaction(SelectRoi)
                .Text = "Select ROI"
                .Image = .GetImage("Select.Roi.Tools.Rectangle")
                .Prompt = "Please create a RECTANGULAR ROI around the SAMPLE AREA then press OK!"
                .Interactive = True
                .Run(doc1, Nothing)
            End With
    
        End Function
  • Pierre --

    Thank you for the assistance.

    I've copied your code into the MODULE / PROJECT that I'm working on and I get a

        NOT AN OBJECT REFERENCE

    error when I try to LOAD the PROJECT.

    An image of the error is attached.

    CHAR 55 on LINE 810 seems to be the last character on the following line
      
                .Overlay = Overlays.OverlayType.ROIOverlay
    
    Is there a library that is not being loaded within

    Imports MediaCy.Addins.Scripting.Workflow
    Imports MediaCy.Addins.Measurements
    Imports MediaCy.Addins.SCalibration.Commands
    Imports MediaCy.Addins.SCalibration
    
    Imports MediaCy.Addins.Measurements
    Imports MediaCy.Addins.LiveOperations
    Imports MediaCy.Addins.SCalibration
    Imports MediaCy.Addins.SCalibration.Commands
    Imports MediaCy.Addins.Scripting.Workflow
    Imports MediaCy.Addins.DataCollector
    Imports MediaCy.Addins.DataCollector.Gadgets
    Imports MediaCy.Addins.Scripting
    Imports MediaCy.Addins.ThresholdTool.Gadgets
    Imports MediaCy.Addins.Measurements
    Imports MediaCy.Addins.ThresholdTool
    Imports MediaCy.Addins.Measurements.Gadgets
    Imports MediaCy.Addins.Measurements.McMMData

    Thanks.

    -- Matt




  • Pierre --

    Thank you very much.

    Making those modifications made

        SelectRoi

    work properly.

    If possible, a tutorial on how to know which IMPORTS and REFERENCES are required for a situation like this would be very helpful.

    Thanks again.

    -- Matt
Sign In or Register to comment.