pumpaij Posted February 4, 2022 Share Posted February 4, 2022 Hello, there's no API for a certain GIS-application to draw title blocks (for plan-production) so I thought that I'd give it a go in Autoit. So far so good but unfortunately I'm stuck now. I've got an array that contains arrays with the X-Position, Y-Position, Width and Height of rectangles I want to draw, I wrote a function called "DrawRectangles" that does the stuff I want to do for each entry in my $testdata-array. ; Data from a text-file. Can also be much larger in rows and columns ; [[XPos, YPos, width, height],[...]] Local $testdata[4][4] = [["00.0", "00.00", "21.00", "29.70"], ["00.05", "00.05", "20.00", "28.70"], ["0.05", "5", "20.00", "05.00"], ["10.00", "00.50", "03.00", "03.00"]] ; Call the function DrawRectangles() for every array in my $testdata-array. For $i = 0 to UBound($testdata)-1 DrawRectangles($testdata[0][$i]) Next Func DrawRectangles($myvar) ; Draw a dummy-rectangle ; Open the preferences-window of this rectangle ; I ControlClick a form and would like to paste the XPos-value of the testdata-array ConsoleWrite("I would fill in the X-Position: " & $myvar & @CRLF) ; Some AutoIT code again ; I ControlClick a form and would like to paste the YPos-value of the testdata-array ConsoleWrite("I would fill in the Y-Position: " & $myvar & @CRLF) ; I ControlClick a form and would like to paste the width-value of the testdata-array ConsoleWrite("I would fill in the width: " & $myvar & @CRLF) ; I ControlClick a form and would like to paste the height-value of the testdata-array ConsoleWrite("I would fill in the height: " & $myvar & @CRLF) ; ControlClick the "OK" Button of the preferences window and repeat for the next array-entry EndFunc In one function call, each one of the four values of the inner array should get pasted into the corresponding fields. But right now the output is as follows: I would fill in the X-Position: 00.0 I would fill in the Y-Position: 00.0 I would fill in the width: 00.0 I would fill in the height: 00.0 I would fill in the X-Position: 00.00 I would fill in the Y-Position: 00.00 I would fill in the width: 00.00 I would fill in the height: 00.00 I would fill in the X-Position: 21.00 I would fill in the Y-Position: 21.00 I would fill in the width: 21.00 I would fill in the height: 21.00 I would fill in the X-Position: 29.70 I would fill in the Y-Position: 29.70 I would fill in the width: 29.70 I would fill in the height: 29.70 And what I want is this: I would fill in the X-Position: 00.0 I would fill in the Y-Position: 00.00 I would fill in the width: 21.00 I would fill in the height: 29.70 I would fill in the X-Position: 00.05 I would fill in the Y-Position: 00.05 I would fill in the width: 20.00 I would fill in the height: 28.70 I would fill in the X-Position: 0.05 I would fill in the Y-Position: 5 I would fill in the width: 20.00 I would fill in the height: 25.00 I would fill in the X-Position: 10.00 I would fill in the Y-Position: 00.50 I would fill in the width: 03.00 I would fill in the height: 03.00 I know it should be a simple loop-thing and I know that the script right now does exactly what the code says. The $myvar-value is the same four times so it gets inserted four times. But no matter what I try, I can't get it to work. Playing around with the Function-Definition always results in errors ("Subscript used on non-accessible variable.:", "Badly formatted "Func" statement.:",...) and playing around with the For-Loop doesn't help me either. If someone could nudge me in the right direction, it'd be highly appreciated. Link to comment Share on other sites More sharing options...
Solution TheXman Posted February 4, 2022 Solution Share Posted February 4, 2022 42 minutes ago, pumpaij said: If someone could nudge me in the right direction, it'd be highly appreciated. There a many ways that it could be done. Here's a "nudge" that shows one of those ways: ; Data from a text-file. Can also be much larger in rows and columns ; [[XPos, YPos, width, height],[...]] Global $testdata[4][4] = [["00.0", "00.00", "21.00", "29.70"], ["00.05", "00.05", "20.00", "28.70"], ["0.05", "5", "20.00", "05.00"], ["10.00", "00.50", "03.00", "03.00"]] ; Call the function DrawRectangles() for every array in my $testdata-array. For $i = 0 to UBound($testdata)-1 DrawRectangles($testdata[$i][0], $testdata[$i][1], $testdata[$i][2], $testdata[$i][3]) Next Func DrawRectangles($x, $y, $w, $h) ; Draw a dummy-rectangle ; Open the preferences-window of this rectangle ; I ControlClick a form and would like to paste the XPos-value of the testdata-array ConsoleWrite("I would fill in the X-Position: " & $x & @CRLF) ; Some AutoIT code again ; I ControlClick a form and would like to paste the YPos-value of the testdata-array ConsoleWrite("I would fill in the Y-Position: " & $y & @CRLF) ; I ControlClick a form and would like to paste the width-value of the testdata-array ConsoleWrite("I would fill in the width: " & $w & @CRLF) ; I ControlClick a form and would like to paste the height-value of the testdata-array ConsoleWrite("I would fill in the height: " & $h & @CRLF) ; ControlClick the "OK" Button of the preferences window and repeat for the next array-entry EndFunc pumpaij 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 (edited) It is not an array embedding arrays (or if you prefer arrays of array). It is just a 2D array (double dimension). Either you need to initialize the array differently or use it as a 2D array. Since there is always 4 coord for each rectangle, I would strongly recommend you keep your 2D array as it it. Now to call a function to draw rect based on this array you could simply do : ; Data from a text-file. Can also be much larger in rows and columns ; [[XPos, YPos, width, height],[...]] Local $testdata[4][4] = [[00.0, 00.00, 21.00, 29.70], [00.05, 00.05, 20.00, 28.70], [0.05, 5, 20.00, 05.00], [10.00, 00.50, 03.00, 03.00]] ; Call the function DrawRectangles() for every array in my $testdata-array. For $i = 0 to UBound($testdata)-1 DrawRectangles($testdata, $i) Next Func DrawRectangles(ByRef $myvar, $iInd) ; Draw a dummy-rectangle ; Open the preferences-window of this rectangle ; I ControlClick a form and would like to paste the XPos-value of the testdata-array ConsoleWrite("I would fill in the X-Position: " & $myvar[$iInd][0] & @CRLF) ; Some AutoIT code again ; I ControlClick a form and would like to paste the YPos-value of the testdata-array ConsoleWrite("I would fill in the Y-Position: " & $myvar[$iInd][1] & @CRLF) ; I ControlClick a form and would like to paste the width-value of the testdata-array ConsoleWrite("I would fill in the width: " & $myvar[$iInd][2] & @CRLF) ; I ControlClick a form and would like to paste the height-value of the testdata-array ConsoleWrite("I would fill in the height: " & $myvar[$iInd][3] & @CRLF) ; ControlClick the "OK" Button of the preferences window and repeat for the next array-entry EndFunc Notice I remove the double-quotes, since they are numbers not strings. If you want to format a number use StringFormat... Edited February 4, 2022 by Nine corrected a small bug pumpaij 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pumpaij Posted February 4, 2022 Author Share Posted February 4, 2022 So that's how it's done. I feel stupid but I was trying all sorts of $i-combinations and couldn't get it to work. Thank you for your quick responses - both methods work well! I'm not sure about the difference between the array of arrays and the 2D-array. Am I correct in visualizing it like this? Array of Arrays: col1 col2 col3 col4 row1 a b c d row2 a b c d row3 a b c d row4 a b c d 2D-Array: col1 col2 col3 col4 row1 [a,b,c,d] [a,b,c,d] [a,b,c,d] [a,b,c,d] Thanks a lot again! Link to comment Share on other sites More sharing options...
Nine Posted February 4, 2022 Share Posted February 4, 2022 1 hour ago, pumpaij said: Am I correct in visualizing it like this? No. Take this simple code to describe an array of arrays : Local $a[] = [1,2,3] ; one array Local $b[] = [1,2,3,4] ; second array Local $embed[] = [$a, $b] ; now array of arrays ConsoleWrite(($embed[1])[3] & @CRLF) ; you can use this approach to access subarrays ; but it will not work if you try to set things that way ; ($embed[1])[3] = 5 ; Instead, you will need to do something like this SetSub($embed[1], 3, 5) ConsoleWrite(($embed[1])[3] & @CRLF) Func SetSub(ByRef $array, $sub, $val) $array[$sub] = $val EndFunc “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now