Jump to content

2-D Array Retrieval


ts29
 Share

Recommended Posts

Okay. I have copied out a UDF example to try and use in my code, however its a disaster. Please help. I want to create a 2D array that is 6 by 6 in dimensions. Now i want AutoIt to scan 36 pixels on a picture.

x x x x x x This is the picture. All the pixels are spaced at the exact same distance apart from every

x x x x x x single adjacent pixel. I want AutoIt to scan the colour and store them into the array.

x x x x x x

x x x x x x

x x x x x x

x x x x x x

Local array [6][6]

UDF EXAMPLE

Local $iMax=6
Local $i
Local $arr[$iMax] = ["1", "2", "3", "4", "5", "6"]
For $i = 0 to $iMax - 1
    ConsoleWrite($arr[$i] & @LF)
Next

How do i apply the UDF example to a 6 by 6 array?

Thanks in advance.

Edited by ts29
Link to comment
Share on other sites

  • Moderators

ts29,

Welcome to the AutoIt forum. :D

You need a couple of loops to help you here:

#include <Array.au3>

Global $aPixelArray[6][6] ; Create a 6x6 array

; You can see that it is currently empty
_ArrayDisplay($aPixelArray)

$iX = 100  ; Put the top left coordinates of the area you want to scan here
$iY = 100

For $x = 0 To 5
    $iPixelX = $iX + $x ; We need to convert the loop value (0 To 5) into the screen coordinates

    For $y = 0 To 5
        $iPixelY = $iY + $y ; And the same here

        ; Now $iPixelX and $iPixelY hold the coordinates of the top left of the area
        ; As you move through the 2 loops, you move through the area like this:

        ; 1   7  13  19
        ; 2   8  14  ... and so on
        ; 3   9  ...
        ; 4  10
        ; 5  11
        ; 6  12

        ; Get the colour of the pixel and store it in the array
        $aPixelArray[$x][$y] = PixelGetColor($iPixelX, $iPixelY)

    Next
Next

; And here is the array that you have filled
_ArrayDisplay($aPixelArray)

I think everything is explained in the comments - 2D arrays look a bit intimidating, but they are not really.

Please ask if anything is unclear. :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Wow! You replied very fast with exactly the stuff i was looking for! I will ++rep if its possible later. Thanks!

But can i ask for more help =3

How do I make it so that the program starts the coordinate system from ONLY the white area in an empty "Untitled - Notepad" window?

Like right below the F in File in Notepad. I dont want to make this program work only on my resolution.. that is why.

Under UDF, I found this.

Run("notepad.exe")
WinWait("[CLASS:Notepad]")
Local $hWnd = WinGetHandle("[CLASS:Notepad]")
Local $sHWND = String($hWnd)    ; Convert to a string
WinSetState(HWnd($sHWND), "", @SW_MINIMIZE)
Sleep(5000) ; Notepad should be minimized
WinClose(HWnd($sHWND))

Does AutoIt let you use the WindowHandle to determine the exact starting top-left coordinates of the white space in Notepad?

Once again, Thank You Very Much for your previous post :D

Link to comment
Share on other sites

  • Moderators

ts29,

You should try opening the Help file...... :D

_WinAPI_ClientToScreen - Converts the client coordinates of a specified point to screen coordinates

So you would use this to convert from Notepad's client 0,0 to screen coordinates to use in the code above. But read the help page carefully - it is not as easy to use as someof the Autoit commands. :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Oh. Heh.

I've put together this from multiple sample codes in the help file

#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#Include <WinAPI.au3>
Opt('MustDeclareVars', 1)
Dim $X, $Y, $colour, $hWnd, $sHWND
$X=0
$Y=0

Run("notepad.exe")
WinWait("[CLASS:Notepad]")
Local $hWnd = WinGetHandle("[CLASS:Notepad]")
Local $sHWND = String($hWnd)    ; Convert to a string

Local Const $tpoint = "int X;int Y"
_WinAPI_ClientToScreen($sHWND, ByRef $tpoint)  <-------- this line, the error points directly to the ByRef


$colour = PixelGetColor ( $X , $Y [, $sHWND] )
MsgBox(0, "_WINAPI_ClientToScreen Example", "Colour of client's x,y position: 0,0 is: " & $colour & @LF)

When i run the .au3 file i get an Error: Error In Expression

I could not find documentation for this error

Would you mind helping me look at it?

Link to comment
Share on other sites

  • Moderators

ts29,

Go and read the Help page for _WinAPI_ClientToScreen carefully as I suggested. In particular, study the example that is put there expressly to show you how it works. You are not using the correct method at present. :huggles:

You have had a lot of code written for you so far - try and solve this bit yourself. But do come back if you are still stuck in a little while and I will offer some more hints. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Oh yeah.. I did not read throroughly enough. So a tagpoint actually needs to be defined with a DLLStructCreate, then the values must be set with a DllStructSetData. It all works smoothly now. Thanks. By the way, how come i cannot edit my own previous posts?

*EDIT

It is 4 posts to edit my own posts :D This is the proof.

Anyway, i tried submitting a feature request via Ticket and i got a rejection due to "Potential Spam" as detected by Akismet. Lol. I was thinking they could make Scite4AutoIt such that when multiple scripts were open, then there could be a small "X" button to close it. But, hey, they dont like the idea.

Anyway, here's the code. It's just copy and paste with a bit of change only. Haha. It's barely an achievement

#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WinAPI.au3>
Opt('MustDeclareVars', 1)
dim $colour

_Main()

Func _Main()
Run("notepad.exe")
WinWait("[CLASS:Notepad]")
Local $hWnd = WinGetHandle("[CLASS:Notepad]")
    Local $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", 0)
    DllStructSetData($tpoint, "Y", 0)
    GUISetState(@SW_SHOW)
    Sleep(1000)
    _WinAPI_ClientToScreen($hwnd, $tpoint)
    $colour = PixelGetColor ( 0 , 0 , $hwnd ) ;REMOVE ALL SQ BRACKETS FROM UDF CODES
    MsgBox(0, "_WINAPI_ClientToScreen Example", "Screen Cordinates of client's x,y position: 0,0 is: " & @LF & _
            "X: " & DllStructGetData($tpoint, "X") & @LF & _
            "Y: " & DllStructGetData($tpoint, "Y") & @LF & _
            "Colour: " & $colour & @LF)
EndFunc   ;==>_Main
Edited by ts29
Link to comment
Share on other sites

  • Moderators

ts29,

I knew you could do it! Well done! :D

To keep out undesirable elements, you need a minimum number of posts before you can access certain forum features. I think it is 5 posts to edit your own posts. Not long to go now.... :huggles:

Good luck with the rest of the project - you know where we are if you need a hand.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I have come to realise it is as important as coding to actually know the exact behaviour you want your program to exhibit, like if window not active, window not maximised, window etcetc blablabla

Edited by ts29
Link to comment
Share on other sites

  • Moderators

ts29,

Now that is worthy of a round of applause. :D You have, in my opinion, understood the most important aspect of any form of programming.

All you have in front of you is a piece of fused silicon with some rare earth impurities - it cannot read your mind, make assumptions, or correct bad typing. All it does is do what you tell it - so you had best get that right. (Actually AutoIt does try to help you rather more than you realise, but the principle is still holds)

You MUST have a good idea of what you are trying to achieve before you start - even to the extent of creating logic flow charts if you are trying to do something reasonably complicated. Otherwise you will soon get lost and your code will rapidly become unmaintainable. I often wonder how many of the scripts we help to "perfect" here could be understood by their creators only a few weeks later. Many of them do not even bother to structure their code in any meaningful way : - for some good examples of how it should be done, go and look at the UDFs included with AutoIt.

So congratulations for the second time today! I look forward to your future contributions here - they should be interesting... :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Nah.. My contributions wont be anything interesting XD

That is, i hope they will, but i doubt it.

Autoit is the language i have delved deepest into, and as you can see from above, its not very deep..

Edited by ts29
Link to comment
Share on other sites

  • Moderators

ts29,

Pity.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...