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
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
0
Best Answers
-
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.
PierrePublic 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
0 -
Sean,
The function GetKeyState gives you the state of the button at the moment the function is called, so if you use a quick click, the button may already be up. Therefore I recommend using other keys, such as Ctrl and Shift to differentiate clicks.
Yuri0
Answers
All three examples worked very well for me.
You can use GetKeyState function to check the state of Right Mouse button. Since the right mouse button is used to show context menu in Image-Pro, you may try to use other button combinations to differentiate clicks, for example Ctrl and/or Shift clicks. They are all handled by GetKeyState function (see https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getkeystate for more details).
Here is the macro that checks the states of the key and mouse buttons clicking on the image:
Yuri