Jump to content

Recommended Posts

Posted

Does autoit support List?

I would like to create an array but without having to declare every variable individually every time, as we move the order around eg adding another projector to a classroom eg A and the script is quite heavily modified as required. It gets tedious having to change all the numbers every time and over time the list will get much larger

write-projector-ini.au3

; list of projectors around the school
; these should be added into list alphabetically
; WARNING - Projector names are case sensitive and must appear exactly as named!
Dim $projector[100]
$projector[1]  = 'A Block,A7_PROJ,44:D2:44:F9:B0:5D,172.16.60.14' ; OK + wiki, HDMI + LAN
$projector[2]  = 'A Block,A8_PROJ,F8:D0:27:00:96:93,172.16.60.37' ; OK + wiki
$projector[3]  = 'A Block,A9_PROJ,64:EB:8C:DA:A7:61,172.16.60.19' ; OK + wiki, HDMI + LAN
$projector[4]  = 'B Block,B6_PROJ,64:EB:8C:D6:92:11,172.16.60.17' ; OK + wiki, VGA + HDMI + LAN
$projector[5]  = 'C Block,C1_PROJ,64:EB:8C:DA:A7:64,172.16.60.16' ; OK + wiki, HDMI + LAN
$projector[6]  = 'C Block,C6_PROJ,00:26:AB:FE:29:A6,172.16.60.15' ; OK + wiki, HDMI + LAN
$projector[7]  = 'C Block,C7_PROJ,64:EB:8C:D4:A7:4C,172.16.60.11' ; OK + wiki, HDMI (only)
$projector[8] = 'C Block,C8_PROJ,F8:D0:27:03:71:FF,172.16.60.39' ; OK + wiki
$projector[9]  = 'C Block,C10_PROJ,64:EB:8C:D5:8C:84,172.16.60.24' ; wiki
$projector[10]  = 'C Block,TEPUNA_PROJ,9C:AE:D3:DF:4F:DB,172.16.60.28' ; OK + wiki, HDMI + LAN
$projector[11] = 'D Block,D2_PROJ,64:EB:8C:D9:6C:C6,172.16.60.6'  ; OK + wiki, VGA + LAN (impractible to use HDMI in this classroom due to length + varnish floor)
$projector[12] = 'D Block,D4_PROJ,44:D2:44:F9:B0:59,172.16.60.13' ; OK + wiki, HDMI + LAN
$projector[13] = 'D Block,D7_PROJ,64:EB:8C:D3:87:B2,172.16.60.18' ; OK + wiki, HDMI + LAN
$projector[14] = 'D Block,D8_PROJ,64:EB:8C:D4:A7:4D,172.16.60.27' ; wiki + VGA (temporary) + LAN
$projector[15] = 'D Block,D9_PROJ,64:EB:8C:D5:8C:CB,172.16.60.2'  ; OK + wiki, HDMI + LAN
$projector[16] = 'E Block,E2_PROJ,64:EB:8C:D9:6C:C9,172.16.60.7'  ; OK + wiki, HDMI + LAN
$projector[17] = 'E Block,E3_PROJ,64:EB:8C:B9:53:9E,172.16.60.25' ; OK + wiki, HDMI + LAN + speaker
$projector[18] = 'E Block,E4_PROJ,64:EB:8C:B9:3B:BC,172.16.60.40' ; TO INSTALL HDMI + LAN
$projector[19] = 'F Block,F3_PROJ,64:EB:8C:B9:69:21,172.16.60.34' ; OK + wiki, HDMI + LAN + speaker
$projector[20] = 'F Block,F4_PROJ,64:EB:8C:B8:68:DB,172.16.60.35' ; OK + wiki, HDMI + LAN + speaker
$projector[21] = 'F Block,F5_PROJ,64:EB:8C:B9:67:75,172.16.60.36' ; OK + wiki, HDMI + LAN + speaker
$projector[22] = 'F Block,F8_PROJ,64:EB:8C:DA:A7:5C,172.16.60.5'  ; OK + wiki, HDMI + Screenbeam (no LAN cable)
$projector[23] = 'F Block,F9_PROJ,64:EB:8C:D6:92:0B,172.16.60.9'  ; OK + wiki, HDMI + LAN
$projector[24] = 'G Block,G4_PROJ,64:EB:8C:D9:F1:63,172.16.60.38' ; OK + wiki
$projector[25] = 'G Block,G5_PROJ,64:EB:8C:D6:92:0A,172.16.60.12' ; OK + wiki, HDMI + LAN
$projector[26] = 'J Block,J1_PROJ,64:EB:8C:D6:92:14,172.16.60.32' ; OK + wiki, HDMI + LAN
$projector[27] = 'J Block,J12L_PROJ,64:EB:8C:2F:68:92,172.16.60.20' ; OK + wiki, HDMI + LAN
$projector[28] = 'J Block,J12R_PROJ,64:EB:8C:2F:E8:B8,172.16.60.21' ; OK + wiki, LAN (only)
$projector[29] = 'J Block,J13_PROJ,64:EB:8C:DA:A7:5D,172.16.60.23' ; OK + wiki, HDMI + LAN
$projector[30] = 'J Block,J15_PROJ,64:EB:8C:A8:01:E5,172.16.60.33' ; OK + wiki, HDMI + LAN
$projector[31] = 'J Block,J17_PROJ,64:EB:8C:D6:EC:C4,172.16.60.31' ; OK + wiki, HDMI (requires LAN)
$projector[32] = 'J Block,J19_PROJ,64:EB:8C:D5:8C:AB,172.16.60.4' ; OK + wiki, HDMI + LAN
$projector[33] = 'K Block,K2_PROJ,64:EB:8C:D3:88:08,172.16.60.29' ; OK + wiki, HDMI + LAN
$projector[34] = 'K Block,K3_PROJ,64:EB:8C:D5:8C:AC,172.16.60.26' ; OK + wiki, HDMI + VGA + LAN (requires dongle)
$projector[35] = 'K Block,K4_PROJ,64:EB:8C:D6:92:15,172.16.60.30' ; OK + wiki, HDMI + LAN
$projector[36] = 'Library,LIB_PROJ,64:EB:8C:D3:88:05,172.16.60.8' ; OK + wiki, HDMI + LAN
$projector[37] = 'Music,M1_PROJ,64:EB:8C:B9:52:F7,172.16.60.22' ; OK + wiki, HDMI + LAN
$projector[38] = 'T Block,T1_PROJ,64:EB:8C:D6:92:17,172.16.60.1'  ; OK + wiki, VGA + LAN
$projector[39] = 'T Block,T2_PROJ,64:EB:8C:DA:A7:88,172.16.60.10' ; OK + wiki, HDMI + LAN
$projector[40] = 'T Block,T6_PROJ,64:EB:8C:D5:8C:A7,172.16.60.3'  ; OK + wiki, HDMI + LAN







; write ini file
$profiledir = 'C:\ProgramData\SEIKO EPSON CORPORATION\EMP NS Connection'
Dim $profilefile[1]
$profilefile[0] = 'Profile_s.plist'
;'$profilefile[1] = 'Profile_sa.plist'

If Not FileExists($profiledir) Then
    DirCreate($profiledir)
EndIf

For $i = 0 To UBound($profilefile) - 1
    FileDelete($profiledir & '\' & $profilefile[$i])
Next

For $i = 0 To UBound($profilefile) - 1
    If $profilefile[$i] <> "" Then
        For $j = 1 To UBound($projector) - 1
            ;ConsoleWrite("$projector" & $j & ": " & $projector[$j] & @CRLF)
            If $projector[$j] <> "" Then
                ; split into array
                Local $aProjector = StringSplit($projector[$j],",")
                Local $Profile = $aProjector[1]
                Local $NM = $aProjector[2]
                Local $UN = StringLower($aProjector[3])
                Local $IP = $aProjector[4]
                ; reset counter to 1 upon different $profile
                If Not IsDeclared("x") Then
                    $x = $Profile
                    $k = 1
                Else
                    If $x = $Profile Then
                        $k = $k + 1
                    Else
                        $x = $Profile
                        $k = 1
                    EndIf
                EndIf
                ConsoleWrite($Profile & " " & $k & @CRLF)
                ; write ini section
                IniWrite($profiledir & '\' & $profilefile[$i], $Profile, "IP"&$k, $IP) ;change
                IniWrite($profiledir & '\' & $profilefile[$i], $Profile, "NM"&$k, $NM) ;change
                IniWrite($profiledir & '\' & $profilefile[$i], $Profile, "ED"&$k, "")
                IniWrite($profiledir & '\' & $profilefile[$i], $Profile, "UN"&$k, $UN) ;change
                IniWrite($profiledir & '\' & $profilefile[$i], $Profile, "CK"&$k, "1")
                If IniWrite($profiledir & '\' & $profilefile[$i], $Profile, "DS"&$k, "0") Then
                    FileWriteLine($profiledir & '\' & $profilefile[$i], "")
                EndIf
            EndIf
        Next
    EndIf
Next

I looked into using a dictionary, however it appears I am doing it wrong

#include 'scriptingdic.au3'

$oObj = _InitDictionary()

$oObj.Add("A Block", "A7_PROJ, 44:D2:44:F9:B0:5D, 172.16.60.14")
$oObj.Add("B Block", "A8_PROJ, F8:D0:27:00:96:93, 172.16.60.37")
$oObj.Add("C Block", "A9_PROJ, 64:EB:8C:DA:A7:61, 172.16.60.19")
$oObj.Add("D Block", "B6_PROJ, 64:EB:8C:D6:92:11, 172.16.60.17")
$oObj.Add("E Block", "C1_PROJ, 64:EB:8C:DA:A7:64, 172.16.60.16")

;MsgBox(0, '', $oObj.Item("A Block"))

Thanks for any tips or advice

 

Posted (edited)

I think SQLite may be too step a learning curve as well as adding more complexity. Also I will still have to rearrange data into the db file, so I would rather leave all the data as text. It's not just me editing the script but other people who should be able to quickly add to it.

With vbs you can just do something like this

Set lDetected = CreateObject("System.Collections.ArrayList") 
lDetected.Add "value1"
lDetected.Add "value2"
lDetected.Add "value3"

For Each u In lDetected
  WScript.Echo u
Next

Is there something as simple in autoit? I would prefer to use autoit as the iniwrite functions are brilliant and clean code. 

Thanks

Edited by NDog
Posted

I don't understand where the problem is
For the array, you shouldn't care about indexes, to add a projector (whatever classroom) just use _ArrayAdd() and _ArraySort()
And the sections/keys are automatically sorted when writing to the ini

  • 2 weeks later...
Posted

if there is a solution to just use _ArrayAdd() thats good.

I guess something along those lines

_ArrayAdd("A Block,A7_PROJ,44:D2:44:F9:B0:5D,172.16.60.14")     ; OK + wiki, HDMI + LAN
_ArrayAdd("A Block,A9_PROJ,64:EB:8C:DA:A7:61,172.16.60.19")     ; OK + wiki, HDMI + LAN

_ArrayAdd("B Block,B6_PROJ,64:EB:8C:D6:92:11,172.16.60.17")     ; OK + wiki, VGA + HDMI + LAN

_ArrayAdd("C Block,C1_PROJ,64:EB:8C:DA:A7:64,172.16.60.16")     ; OK + wiki, HDMI + LAN
_ArrayAdd("C Block,C6_PROJ,00:26:AB:FE:29:A6,172.16.60.15")     ; OK + wiki, HDMI + LAN
_ArrayAdd("C Block,C7_PROJ,64:EB:8C:D4:A7:4C,172.16.60.11")     ; OK + wiki, HDMI (only)
_ArrayAdd("C Block,C8_PROJ,F8:D0:27:03:71:FF,172.16.60.39")     ; 
_ArrayAdd("C Block,C9_PROJ,F8:D0:27:00:96:93,172.16.60.37")     ; OK + wiki, HDMI + LAN cable connected but not live
_ArrayAdd("C Block,C10_PROJ,64:EB:8C:D5:8C:84,172.16.60.24")    ; ?
_ArrayAdd("C Block,TEPUNA_PROJ,9C:AE:D3:DF:4F:DB,172.16.60.28") ; OK + wiki, HDMI + LAN

Thanks for point in the right direction 

Posted

Maybe a dictionary, but with maplike add/remove functions? 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted
8 hours ago, NDog said:

if there is a solution to just use _ArrayAdd() thats good.

In fact I thought of something like this

#include <Array.au3>
Local $projector[0][4]

_ArrayAdd($projector, "A Block,A7_PROJ,44:D2:44:F9:B0:5D,172.16.60.14", 0, ",")     ; OK + wiki, HDMI + LAN
_ArrayAdd($projector, "A Block,A9_PROJ,64:EB:8C:DA:A7:61,172.16.60.19", 0, ",")     ; OK + wiki, HDMI + LAN
_ArrayAdd($projector, "B Block,B6_PROJ,64:EB:8C:D6:92:11,172.16.60.17", 0, ",")     ; OK + wiki, VGA + HDMI + LAN
_ArrayAdd($projector, "C Block,C1_PROJ,64:EB:8C:DA:A7:64,172.16.60.16", 0, ",")     ; OK + wiki, HDMI + LAN
_ArrayAdd($projector, "C Block,C6_PROJ,00:26:AB:FE:29:A6,172.16.60.15", 0, ",")     ; OK + wiki, HDMI + LAN
_ArrayAdd($projector, "C Block,C7_PROJ,64:EB:8C:D4:A7:4C,172.16.60.11", 0, ",")     ; OK + wiki, HDMI (only)
_ArrayAdd($projector, "C Block,C8_PROJ,F8:D0:27:03:71:FF,172.16.60.39", 0, ",")     ; 
_ArrayAdd($projector, "C Block,C9_PROJ,F8:D0:27:00:96:93,172.16.60.37", 0, ",")     ; OK + wiki, HDMI + LAN cable connected but not live
_ArrayAdd($projector, "C Block,C10_PROJ,64:EB:8C:D5:8C:84,172.16.60.24", 0, ",")    ; ?
_ArrayAdd($projector, "C Block,TEPUNA_PROJ,9C:AE:D3:DF:4F:DB,172.16.60.28", 0, ",") ; OK + wiki, HDMI + LAN

_ArrayDisplay($projector, "2D array") 

_ArrayAdd($projector, "B Block,B7_PROJ,64:EB:8C:D6:92:11,172.16.60.18", 0, ",")     ; OK + wiki, VGA + HDMI + LAN
_ArraySort($projector)

_ArrayDisplay($projector, "B7 element added, array sorted")

 

Posted

Store the projectors data inside a text file. Use _FileReadToArray() to automaticly create an array based on this file.

You can then add or remove lines inside the text file and the array will adapt itself to it, no need to change the numbers by hand :)

You can even add projectors data in non-alphabetical order and use _ArraySort() to sort your projector in the right order.

Posted (edited)

Oh, and don't forget to use _FileWriteFromArray to write them back out to your text file before exiting your program.

It seems you are using your AutoIT source code to store your data, rather than just manipulate it. After a few entries it gets a bit unwieldy. It appears to be suitable for storing as 'csv' data.
Isn't this something you could do using a spreadsheet or a database? You could also edit your text file directly with a text editor.

Edited by Confuzzled

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
  • Recently Browsing   0 members

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