Sign in to follow this  
Followers 0
PERTU

Help with _ArrayMax

9 posts in this topic

Hi,

I have a bunch of file in a directory that represent the version of a scene in ToonBoom Harmony. Here are the files I have in the directory.

v1.stage

v10.stage

v11.stage

v12.stage

v2.stage

v3.stage

v4.stage

v5.stage

v6.stage

v7.stage

v8.stage

v9.stage

v1.stage~

v10.stage~

v11.stage~

v12.stage~

v2.stage~

v3.stage~

v4.stage~

v5.stage~

v6.stage~

v7.stage~

v8.stage~

v9.stage~

I want my script to return the number of the highest version with 3 digits. Like this "012". But my script will return "009". If I have less than 10 versions, the script return the correct number.

Here is my script:

$ArVersion = _FileListToArray($dirstage)


$version = StringRight("00" & StringMid(_ArrayMax( $ArVersion, 0, 1), 2, StringInStr(_ArrayMax( $ArVersion, 0, 1), ".") -2), 3)

Anyone knows how to fix this?

Thank you,

Olivier.

Share this post


Link to post
Share on other sites



Hi,

the problem: string '9' is greater than string '12'.

You must select numbers from string and then use _ArrayMax.

See here:

#include <array.au3>
#include <string.au3>
Dim $version, $ArVersion[24]= _
['v1.stage', _
'v10.stage', _
'v11.stage', _
'v12.stage', _
'v2.stage', _
'v3.stage', _
'v4.stage', _
'v5.stage', _
'v6.stage', _
'v7.stage', _
'v8.stage', _
'v9.stage', _
'v1.stage~', _
'v10.stage~', _
'v11.stage~', _
'v12.stage~', _
'v2.stage~', _
'v3.stage~', _
'v4.stage~', _
'v5.stage~', _
'v6.stage~', _
'v7.stage~', _
'v8.stage~', _
'v9.stage~']

_SelNumberFromStr()
$version = StringRight('00' &  _ArrayMax($ArVersion, 1), 3 )
MsgBox(0, 'Current Version', $version)


Func _SelNumberFromStr()
    For $i = 0 To UBound($ArVersion)-1
        $number = _StringBetween($ArVersion[$i], 'v', '.')
        $ArVersion[$i] = Number($number[0])
    Next
EndFunc

Best Regards BugFix  

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

BugFix, thank you for the code.

I'm trying to understand it. I tried your code exactly as you posted and It worked. I tried to put it in my script but I get an error.

Here is the error:

CODE
Line 117 (File ... .au3"):

$number = _StringBetween($ArVersion[$i], 'v', '.')

$number = ^ERROR

Error: Unknown function name.

And here is my complete script. Line 117 is the fourth from the bottom.

#Include <File.au3>
#Include <Array.au3>

$defepisode = IniRead(@ScriptDir & "\MoveRenderset.ini", "Parameters", "LastUsedEpisode", "aa") ;Lecture du denier episode dans le .ini

$dir = "E:\usadata000"

$defscene = "1"

While 1

$episode = InputBox("MoveRenderset", "Quel épisode?", $defepisode , "")
If @Error=1 Then
    Exit
EndIf
$episode = StringRight( $episode , 2)

IniWrite(@ScriptDir & "\MoveRenderset.ini", "Parameters", "LastUsedEpisode", $episode)




$direpisode = $dir & "\" & "go_" & $episode
_FileListToArray($direpisode)
If @Error=1 Then
    _FileWriteLog(@ScriptDir & "\MoveRenderset.log"," L'épisode " & $episode & " est introuvable" & @CR & @CR & @CR)
    MsgBox (16,"MoveRenderset","L'épisode " & $episode & " est introuvable")
    Exit
EndIf

$scene = InputBox("MoveRenderset", "Quel scène?", $defscene , "")
If @Error=1 Then
    Exit
EndIf

; Vérifie si la scène contient une lettre et trouve le numéro de scène.
$scene = "00" & $scene  
$digit = StringIsDigit($scene)
If $digit = 1 Then
$scene = StringRight($scene, 3)
Else
$scene = StringRight($scene, 4)
EndIf


$dirscene = $direpisode & "\scene-" & $scene

$dirframes = $dirscene & "\frames"

$dirstage = $dirscene & "\stage"



_FileListToArray($dirscene)
If @Error=1 Then
    _FileWriteLog(@ScriptDir & "\MoveRenderset.log"," La scene " & $scene & " est introuvable" & @CR & @CR & @CR)
    MsgBox (16,"MoveRenderset","La scene " & $scene & " est introuvable")
    Exit
EndIf

$ArFrames = _FileListToArray($dirframes)

$frames = _ArrayToString( $ArFrames,@TAB, 0, 0 )

MsgBox(0, "", $frames)

If @Error=1 Then
    MsgBox (16,"MoveRenderset","Le dossier ""frames"" est vide")
    Exit
EndIf

; Déterminer la version de la scène
$ArVersion = _FileListToArray($dirstage)
_SelNumberFromStr()
$version = StringRight('00' &  _ArrayMax($ArVersion, 1), 3 )
MsgBox(0, 'Current Version', $version)





$dirrenderset = "E:\Renderset\" & $episode & "\" & $episode & $scene & "_" & $version

DirCreate($dirrenderset)

FileMove($dirframes & "\*.tga", $dirrenderset & "\*.tga")

$ArFrames = _FileListToArray($dirrenderset)

$frames = _ArrayToString( $ArFrames,@TAB, 0, 0 )

_FileWriteLog(@ScriptDir & "\MoveRenderset.log","//-----------------------" & @CR & @CR & "Épisode: " & $episode & @CR & "Scène: " & $scene & @CR & "Version: " & $version & @CR & "Nb de frames: " & $frames  & @CR & @CR & "Déplacement terminé   -----------------------\\" & @CR & @CR & @CR)


MsgBox(0, "MoveRenderset", "Épisode: " & $episode & @CR & "Scène: " & $scene & @CR & "Version: " & $version & @CR & "Nb de frames: " & $frames  & @CR & @CR & "Déplacement terminé")

$defepisode = $episode

$defscene = $scene + 1

WEnd


Func _SelNumberFromStr()
    For $i = 0 To UBound($ArVersion)-1
        $number = _StringBetween($ArVersion[$i], 'v', '.') ;line 117
        $ArVersion[$i] = Number($number[0])
    Next
EndFunc

My script is not optimal, I'm kind of new to AutoIt. Do you know why I get this error?

Thank you,

Olivier.

Edited by PERTU

Share this post


Link to post
Share on other sites

You forgot:

#include <string.au3>
Thank you GMK, I'll try that.

Olivier.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I get a different error now:

CODE
Line 119 (File ... .au3"):

$ArVersion[$i] = Number($number[0])

$ArVersion[$i] = Number($number^ERROR

Error: Subscript used with non-Array variable.

Here is my script, Line 119 is the third from the bottom.

#Include <File.au3>
#Include <Array.au3>
#include <string.au3>

$defepisode = IniRead(@ScriptDir & "\MoveRenderset.ini", "Parameters", "LastUsedEpisode", "aa") ;Lecture du denier episode dans le .ini

$dir = "E:\usadata000"

$defscene = "1"

While 1

$episode = InputBox("MoveRenderset", "Quel épisode?", $defepisode , "")
If @Error=1 Then
    Exit
EndIf
$episode = StringRight( $episode , 2)

IniWrite(@ScriptDir & "\MoveRenderset.ini", "Parameters", "LastUsedEpisode", $episode)




$direpisode = $dir & "\" & "go_" & $episode
_FileListToArray($direpisode)
If @Error=1 Then
    _FileWriteLog(@ScriptDir & "\MoveRenderset.log"," L'épisode " & $episode & " est introuvable" & @CR & @CR & @CR)
    MsgBox (16,"MoveRenderset","L'épisode " & $episode & " est introuvable")
    Exit
EndIf

$scene = InputBox("MoveRenderset", "Quel scène?", $defscene , "")
If @Error=1 Then
    Exit
EndIf

; Vérifie si la scène contient une lettre et trouve le numéro de scène.
$scene = "00" & $scene  
$digit = StringIsDigit($scene)
If $digit = 1 Then
$scene = StringRight($scene, 3)
Else
$scene = StringRight($scene, 4)
EndIf


$dirscene = $direpisode & "\scene-" & $scene

$dirframes = $dirscene & "\frames"

$dirstage = $dirscene & "\stage"



_FileListToArray($dirscene)
If @Error=1 Then
    _FileWriteLog(@ScriptDir & "\MoveRenderset.log"," La scene " & $scene & " est introuvable" & @CR & @CR & @CR)
    MsgBox (16,"MoveRenderset","La scene " & $scene & " est introuvable")
    Exit
EndIf

$ArFrames = _FileListToArray($dirframes)

$frames = _ArrayToString( $ArFrames,@TAB, 0, 0 )

MsgBox(0, "", $frames)

If @Error=1 Then
    MsgBox (16,"MoveRenderset","Le dossier ""frames"" est vide")
    Exit
EndIf

; Déterminer la version de la scène
$ArVersion = _FileListToArray($dirstage)
_SelNumberFromStr()
$version = StringRight('00' &  _ArrayMax($ArVersion, 1), 3 )
MsgBox(0, 'Current Version', $version)





$dirrenderset = "E:\Renderset\" & $episode & "\" & $episode & $scene & "_" & $version

DirCreate($dirrenderset)

FileMove($dirframes & "\*.tga", $dirrenderset & "\*.tga")

$ArFrames = _FileListToArray($dirrenderset)

$frames = _ArrayToString( $ArFrames,@TAB, 0, 0 )

_FileWriteLog(@ScriptDir & "\MoveRenderset.log","//-----------------------" & @CR & @CR & "Épisode: " & $episode & @CR & "Scène: " & $scene & @CR & "Version: " & $version & @CR & "Nb de frames: " & $frames  & @CR & @CR & "Déplacement terminé   -----------------------\\" & @CR & @CR & @CR)


MsgBox(0, "MoveRenderset", "Épisode: " & $episode & @CR & "Scène: " & $scene & @CR & "Version: " & $version & @CR & "Nb de frames: " & $frames  & @CR & @CR & "Déplacement terminé")

$defepisode = $episode

$defscene = $scene + 1

WEnd


Func _SelNumberFromStr()
    For $i = 0 To UBound($ArVersion)-1
        $number = _StringBetween($ArVersion[$i], 'v', '.')
        $ArVersion[$i] = Number($number[0]) ;Line 119
    Next
EndFunc

Anyone knows what is wrong?

Thanks.

Edited by PERTU

Share this post


Link to post
Share on other sites

I had 2 other bug with my script beside the current version bug. I have fixed both of them, but the current version is still not working. So I ask again If someone can help me.

Thank you,

Olivier.

Share this post


Link to post
Share on other sites

For $i = 0 To UBound($ArVersion)-1
    $number = _StringBetween($ArVersion[$i], 'v', '.')
    If IsArray($number) Then
        $ArVersion[$i] = Number($number[0]) ;Line 119
    EndIf
EndIf


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
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
Sign in to follow this  
Followers 0