Jump to content

OT: Script check: "_CreateTypeData()"


Go to solution Solved by pixelsearch,

Recommended Posts

Posted

Good day,

I would appreciate it someone who "glean" over this script to ensure that all looks "Okay!" [...indeed, if this be a reasonable request?" If not, I i will summarily  remove the posting.

The procedure:

1) Select one of four different types of Session "Sets".
2) Within these four different types Session "Sets" select the appropriate source wave file data.
• This selected data is then "read" into memory
• This read data will be employed to create "named copies" of one-of-four master data files
3) Select the destination folder for the named copies.
4) The memorized data is read and copies are made of one-of-the-four master data files

Here is the script:

; -----------------------------------------------
; With the assistance of...and the gratitude of...ioa747, AndrewG, and pixelsearch!
; Date: November 5th, 2024
; -----------------------------------------------
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable is always to be enabled!!
Global $_sTypeSetName = "" ; Disable when any of the other variables are deployed
;Global $_sTypeSetName = "F:\Audio\Type_1"
;Global $_sTypeSetName = "F:\Audio\Type_2"
;Global $_sTypeSetName = "F:\Audio\Type_3"
;Global $_sTypeSetName = "F:\Audio\Type_4"
; -----------------------------------------------
_CreateTypeData($_sTypeSetName)
; -----------------------------------------------
Func _CreateTypeData($_sTypeSetName)
    ; Script concepts provided by ioa747...
    Local $_sMasterType1Edl = "Type1.edl"
    Local $_sMasterType2Edl = "Type2.edl"
    Local $_sMasterType3Edl = "Type3.edl"
    Local $_sMasterType4Edl = "Type4.edl"
    ; -----------------------------------------------
    Local $_ConfirmCreate = MsgBox(4, "NOTICE!", "Create " & StringMid($_sTypeSetName, 10, 6) & " Session Data from .wav data?")
    ; ------------------------------------------------------
    If $_ConfirmCreate = 6 Then
        Local $_sMessage = "Select the required .wav data..."
        ; -----------------------------------------------
        Local $_sFileOpenDialog = FileOpenDialog($_sMessage, $_sTypeSetName & "\wav", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
        Local $_WavFiles = StringSplit($_sFileOpenDialog, "|")
        ; ------------------------------------------------------
        Local $_DestMessage = "Select the Destination folder for the Session .edl file(s)..."
        Local $_DestFolder = FileSelectFolder($_DestMessage, $_sTypeSetName)
        ; -----------------------------------------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No destination folder selected. Exiting.")
            Return
            ; ------------------------------------------------------
        ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_1" Then
            $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType1Edl
            ; -----------------
        ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_2" Then
            $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType2Edl
            ; -----------------
        ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_3" Then
            $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType3Edl
            ; -----------------
        ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_4" Then
            $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType4Edl
            ; -----------------
        Else
            MsgBox($MB_ICONERROR, "Error", "The " & $_MasterEdlFile & " file was not found.")
            Return
        EndIf
        ; ------------------------------------------------------
        ; Script concepts provided by pixelsearch...
        If $_WavFiles[0] = 1 Then     ; If only one file was selected by the user...
            Local $iPos_LastBackslash = StringInStr($_WavFiles[1], "\", 0, -1) ; -1 starts from the right (+++)
            ReDim $_WavFiles[3]
            $_WavFiles[2] = StringMid($_WavFiles[1], $iPos_LastBackslash + 1) ; The file name
            $_WavFiles[1] = StringLeft($_WavFiles[1], $iPos_LastBackslash - 1) ; The path (without last backslash)
            $_WavFiles[0] = 2
        EndIf
        ; ------------------------------------------------------
        Local $_sWavFolder = $_WavFiles[1]
        ; ------------------------------------------------------
        For $i = 1 To $_WavFiles[0]        ; If multiple files were selected by the user...
            Local $_WavFileName = $_sWavFolder & "\" & $_WavFiles[$i]
            Local $_WavBaseName = StringTrimRight($_WavFiles[$i], 4)
            ; -----------------
            Local $_NewEdlFile = $_DestFolder & "\" & $_WavBaseName & ".edl"
            ; -----------------
            FileCopy($_MasterEdlFile, $_NewEdlFile, $FC_NOOVERWRITE) ; Suggested by AndrewG
        Next
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success", "The " & StringMid($_sTypeSetName, 10, 6) & " file(s) have been created successfully.")
        ; ------------------------------------------------------
    ElseIf $_ConfirmCreate = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
    EndIf
EndFunc   ;==>_CreateTypeData
; -----------------------------------------------

I wish to thank the following for their immeasurable assistance, ioa747, AndrewG, and pixelsearch!

Thank you!

Posted

in the line
For $i = 1 To $_WavFiles[0]


don't forget that the first line has only the folder
Local $_sWavFolder = $_WavFiles[1]


so you start from the second one

For $i = 2 To $_WavFiles[0]

I know that I know nothing

Posted (edited)

@mr-es335 I did a quick test with your script (after creating all the paths needed on my computer)

1) Major issue with the following line :

For $i = 1 To $_WavFiles[0] ; If multiple files were selected by the user...

1 is the element in the array that contains the path (it is not a wav file name) so your loop should start from 2 :

For $i = 2 To $_WavFiles[0] ; one or several wav files were selected by the user...

2) FileOpenDialog ; no error checking ?
If we cancel the FileOpenDialog window (e.g. no wav file selected) then a file named ".edl" will be created somewhere (it happened to me) . As you did check @error correctly for FileSelectFolder, then you should also do the error checking for FileOpenDialog

After having fixed this, then your script seems to work, though I tested it much too quickly.

Edited by pixelsearch
removed the return checking on FileCopy as $FC_NOOVERWRITE is present.

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

Good day guys,

Thanks to you both for the suggestions. It IS interesting that both of you deduced the same initial error!

Yes, I know about the "FileOpenDialog" issue. Just not too sure how to go about fixing this one!

As a point of interest... from "Ask Difference", "Methodical vs. Logical — What's the Difference?"...one of the best comparisons and explanations  that I have ever come across...

"Methodical involves a systematic, orderly approach to tasks, focusing on step-by-step procedures. Logical refers to clear, rational thinking based on reasoning."

This is precisely why I find some aspects of programming so very difficult to grasp. I AM the first...and most definitely, I am NOT the latter! I do hope that this makes sense?

Posted (edited)

pixelsearch,

With regards to the "FileOpenDialog" issue...I managed to strip the script down to the following:

; -----------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable is always to be enabled!!
Global $_sTypeSetName = "" ; Disable when any of the other variables are deployed
;Global $_sTypeSetName = "F:\Audio\Type_1"
;Global $_sTypeSetName = "F:\Audio\Type_2"
;Global $_sTypeSetName = "F:\Audio\Type_3"
;Global $_sTypeSetName = "F:\Audio\Type_4"
; -----------------------------------------------
_FileOpenDialog()
; -----------------------------------------------
Func _FileOpenDialog()
    Local $_ConfirmCreate = MsgBox(4, "NOTICE!", "Create " & StringMid($_sTypeSetName, 10, 6) & " Session Data from .wav data?")
    ; ------------------------------------------------------
    If $_ConfirmCreate = 6 Then
        Local $_sMessage = "Select the required .wav data..."
        ; -----------------------------------------------
        Local $_sFileOpenDialog = FileOpenDialog($_sMessage, $_sTypeSetName & "\wav", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
        ;MsgBox($MB_TOPMOST, "", $_sFileOpenDialog)
        ; -----------------------------------------------
        ; Recommended by pixelsearch
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No source folder selected. Exiting.")
            Return
        Endif
        ; ------------------------------------------------------
        Local $_DestMessage = "Select the Destination folder for the Session .edl file(s)..."
        Local $_DestFolder = FileSelectFolder($_DestMessage, $_sTypeSetName)
        ;MsgBox($MB_TOPMOST, "", $_DestFolder)
        ; -----------------------------------------------
        If @error Then
            MsgBox($MB_ICONERROR, "Error", "No destination folder selected. Exiting.")
            Return
        Endif
        ; ------------------------------------------------------
    ElseIf $_ConfirmCreate = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
    EndIf
EndFunc   ;==>_FileOpenDialog
; -----------------------------------------------

The above script "now appears" to be working as it should!?!

However, I would prefer NOT to exit the script. In the DOS days, I could employ "goto's".  As Autoit does not employ "goto's", I might assume that this is where "Functions" would be deployed? For example:

; -----------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable is always to be enabled!!
Global $_sTypeSetName = "" ; Disable when any of the other variables are deployed
;Global $_sTypeSetName = "F:\Audio\Type_1"
;Global $_sTypeSetName = "F:\Audio\Type_2"
;Global $_sTypeSetName = "F:\Audio\Type_3"
;Global $_sTypeSetName = "F:\Audio\Type_4"
; -----------------------------------------------
_SelectWavData()
; -----------------------------------------------
Func _SelectWavData()
    Local $_ConfirmCreate = MsgBox(4, "NOTICE!", "Create " & StringMid($_sTypeSetName, 10, 6) & " Session Data from .wav data?")
    ; ------------------------------------------------------
    If $_ConfirmCreate = 6 Then
        _FileOpenDialog()
        _FileSelectFolder()
    ElseIf $_ConfirmCreate = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
    EndIf
EndFunc   ;==>_SelectWavData
; -----------------------------------------------
Func _FileOpenDialog()
    Local $_ConfirmOpenDialog = MsgBox(4, "Notice!", "Select the required source .wav file data...")
    ; ------------------------------------------------------
    If $_ConfirmOpenDialog = 6 Then
        Local $_sFileOpenDialog = FileOpenDialog("", $_sTypeSetName & "\wav", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
    ElseIf $_ConfirmOpenDialog = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
    EndIf
EndFunc   ;==>_FileOpenDialog
; -----------------------------------------------
Func _FileSelectFolder()
    Local $_ConfirmFileSelect = MsgBox(4, "Notice!", "Select the Destination folder for the Session .edl file(s)...")
    ; ------------------------------------------------------
    If $_ConfirmFileSelect = 6 Then
        Local $_DestFolder = FileSelectFolder("", $_sTypeSetName)
    ElseIf $_ConfirmFileSelect = 7 Then
        MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
    EndIf
EndFunc   ;==>_FileSelectFolder
; -----------------------------------------------

So, how is the above?!?

Note: The ONLY issue now is, "How to make this all work together with the original 'CreateTypeData()' script?"

Edited by mr-es335
Additions
  • Solution
Posted (edited)

All together ? Like this :

#include <File.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $_MasterEdlFile = "" ; This global variable is always to be enabled!!
Global $_sMasterType1Edl = "Type1.edl"
Global $_sMasterType2Edl = "Type2.edl"
Global $_sMasterType3Edl = "Type3.edl"
Global $_sMasterType4Edl = "Type4.edl"

; Global $_sTypeSetName = "" ; Disable when any of the other variables are deployed
Global $_sTypeSetName = "F:\Audio\Type_1"
; Global $_sTypeSetName = "F:\Audio\Type_2"
; Global $_sTypeSetName = "F:\Audio\Type_3"
; Global $_sTypeSetName = "F:\Audio\Type_4"
; -----------------------------------------------
_CreateTypeData($_sTypeSetName)

; -----------------------------------------------
Func _CreateTypeData($_sTypeSetName)

    Local $_ConfirmCreate = MsgBox($MB_YESNO, "NOTICE!", "Create " & StringMid($_sTypeSetName, 10, 6) & " Session Data from .wav data?")
    ; ------------------------------------------------------
    If $_ConfirmCreate = $IDYES Then
        Local $_WavFiles = _FileOpenDialog()
        Local $_DestFolder = _FileSelectFolder()
        Local $_sWavFolder = $_WavFiles[1] ; contains only a path, no matter the user selected 1 or more files
        ; ------------------------------------------------------
        For $i = 2 To $_WavFiles[0] ; 1st file name in element 2 etc...
            Local $_WavFileName = $_sWavFolder & "\" & $_WavFiles[$i]
            Local $_WavBaseName = StringTrimRight($_WavFiles[$i], 4)
            ; -----------------
            Local $_NewEdlFile = $_DestFolder & "\" & $_WavBaseName & ".edl"
            ; -----------------
            FileCopy($_MasterEdlFile, $_NewEdlFile, $FC_NOOVERWRITE)
        Next
        ; -----------------
        MsgBox($MB_ICONINFORMATION, "Success", "The " & StringMid($_sTypeSetName, 10, 6) & " file(s) have been created successfully.")
        ; ------------------------------------------------------
    Else ; $IDNO
        MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
        Exit
    EndIf
EndFunc   ;==>_CreateTypeData

; -----------------------------------------------
Func _FileOpenDialog()

    While 1
        Local $_sMessage = "Select the required source .wav data..."
        Local $_ConfirmOpenDialog = MsgBox($MB_YESNO, "Notice!", $_sMessage)
        ; ------------------------------------------------------
        If $_ConfirmOpenDialog = $IDYES Then
            Local $_sFileOpenDialog = FileOpenDialog($_sMessage, $_sTypeSetName & "\wav", "Wave Data (*.wav;)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
            If @error Then
                MsgBox($MB_ICONERROR, "Error", "No wav file(s) selected.")
                ContinueLoop ; While 1
            Endif
            Local $_WavFiles = StringSplit($_sFileOpenDialog, "|")
            If $_WavFiles[0] = 1 Then ; if only one file was selected by the user...
                Local $iPos_LastBackslash = StringInStr($_WavFiles[1], "\", 0, -1) ; -1 starts from the right (+++)
                ReDim $_WavFiles[3]
                $_WavFiles[2] = StringMid($_WavFiles[1], $iPos_LastBackslash + 1) ; The file name
                $_WavFiles[1] = StringLeft($_WavFiles[1], $iPos_LastBackslash - 1) ; The path (without last backslash)
                $_WavFiles[0] = 2
            EndIf
            Return $_WavFiles
        Else ; $IDNO
            MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
            Exit
        EndIf
    WEnd
EndFunc   ;==>_FileOpenDialog

; -----------------------------------------------
Func _FileSelectFolder()

    While 1
        Local $_Message = "Select the Destination folder for the Session .edl file(s)..."
        Local $_ConfirmFileSelect = MsgBox($MB_YESNO, "Notice!", $_Message)
        ; ------------------------------------------------------
        If $_ConfirmFileSelect = $IDYES Then
            Local $_DestFolder = FileSelectFolder($_Message, $_sTypeSetName)
            If @error Then
                MsgBox($MB_ICONERROR, "Error", "No destination folder selected.")
                ContinueLoop ; While 1
                ; ------------------------------------------------------
            ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_1" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType1Edl
                ; -----------------
            ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_2" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType2Edl
                ; -----------------
            ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_3" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType3Edl
                ; -----------------
            ElseIf StringMid($_sTypeSetName, 10, 6) = "Type_4" Then
                $_MasterEdlFile = "G:\Session_Master\Show\Session_Data\" & $_sMasterType4Edl
                ; -----------------
            Else
                MsgBox($MB_ICONERROR, "Error", "The " & $_MasterEdlFile & " file was not found.")
                ContinueLoop ; While 1
            EndIf
            Return $_DestFolder
        Else ; $IDNO
            MsgBox($MB_ICONINFORMATION, "Cancelled", "The operation was cancelled by the user.")
            Exit
        EndIf
    WEnd
EndFunc   ;==>_FileSelectFolder

 

Edited by pixelsearch

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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...