Help on PixelLocation Property

I am trying to use the PixelLocation Property to select a pixel location on an image and return the coordinates of that location. I am struggling to craft the right construct to do this.

In image pro 7  I use something like the following code to return point

Dim MyDocID as Long
Dim myPt as POINTAPI
MyDocID = IpDocClick("Select Point", myPt)
If MyDocID <0 then
  Exit Sub
Else
  Debug.print myPt.x
End If

Can anyone help me?

Thanks

Best Answer

  • edited August 2017 Accepted Answer
    Hello Sean,

    The command is Automate.ScriptingCommands.ClickOnWorkspace, demonstrated here in a macro created with the designer as well as a couple of plain functions.

    Pierre
        Public Function GetPixelLocation() As SimpleScript
            GetPixelLocation = New SimpleScript
            Dim window1, doc1
    
            With Application.WindowCommands.Active(GetPixelLocation)
                .Run(window1)
            End With
    
            With Automate.ScriptingCommands.ClickOnWorkspace(GetPixelLocation)
                .Prompt = "Please select an image location."
                .SelectDocuments = True ' The output can be a document or a window
                .Run(window1, doc1, Nothing)
                ' Display the document name and pixel location in the output panel once the command is done
                If .Status=McCommand.TaskStatus.IsProcessed Then
                    ThisApplication.Output.Show
                    ThisApplication.Output.PrintMessage .Output.Value.Name
                    ThisApplication.Output.PrintMessage .PixelLocation.Value.ToString()
                End If
            End With
    
        End Function
    
        ' Return the pixel location in the active window
        Public Function GetPixelLocation2() As System.Drawing.PointF
    
            With Automate.ScriptingCommands.ClickOnWorkspace(Nothing)
                .Run(ThisApplication.ActiveWindow, Nothing, GetPixelLocation2)
                Debug.Print GetPixelLocation2.ToString()
            End With
    
        End Function
    
        ' Return the pixel location and prompt in the image strip first
        Public Function GetPixelLocation3() As System.Drawing.PointF
    
            With Automate.ScriptingCommands.ClickOnWorkspace(Nothing)
                .Run(Nothing, Nothing, GetPixelLocation3)
                Debug.Print GetPixelLocation3.ToString()
            End With
    
        End Function
    

Answers

Sign In or Register to comment.