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
-
Thanks Pierre
All three examples worked very well for me.
0 -
The examples above have worked well for me, but I now want to add an additional capability.I see that when I use either the right or left mouse button, it will return pixel location, but I want to perform different actions dependent on which button is clicked. Is there a way to return pixel location and which button was clicked?Thank you0
-
Hi Sean,
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:Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer Const VK_CONTROL As Integer = &H11 'Ctrl Const VK_SHIFT As Integer= &H10'shift Const VK_RBUTTON As Integer =&H02'right mouse button Private Function IsDown(ByVal nVirtKey As Long) As Boolean Return (GetKeyState(nVirtKey) And &H8000) <>0 End Function 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 'Dim bCtrl As Boolean= GetKeyState(VK_CONTROL) < 0 If .Status=McCommand.TaskStatus.IsProcessed Then ThisApplication.Output.Show ThisApplication.Output.PrintMessage "Ctrl is down = " & (IsDown(VK_CONTROL)).ToString ThisApplication.Output.PrintMessage "Shift is down = " & (IsDown(VK_SHIFT)).ToString ThisApplication.Output.PrintMessage "Right mouse button = " & (IsDown(VK_RBUTTON)).ToString ThisApplication.Output.PrintMessage .Output.Value.Name ThisApplication.Output.PrintMessage .PixelLocation.Value.ToString() End If End With End Function
Yuri
0 -
Thanks YuriThat worked pretty well. However, I have to hold the mouse button down for it to be recognized. If I do a normal quick click, it is not recognized.I tried different McCommand.TaskStatus options to no avail. Do I need to use a timer or do you have some other suggestions to catch my quick clicks?Sean0
-
Thanks again Yuri. I ended up using Shift as you suggested and that works.Sean0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions