Can a DOpus.dlg object be defined and used within the function/event OnGetNewName?
This script works using DOus.dlg:
' Create a Dialog object.
DOpus.ClearOutput
Set dlg = DOpus.Dlg
' Initialise the object to display a drop-down control that lets the user pick one option from a list of many
dlg.window = DOpus.Listers(0)
dlg.message = Drop-down list dialog message
dlg.title = Drop-down Dialog Title
dlg.buttons = OK|Cancel
dlg.choices = DOpus.Create.Vector(1 Choice 1, 2 Choice 2, 3Choice 3, 4 Choice 4, Maxalt 0.5)
dlg.selection = 0
' Show the dialog and print the results to the script log '
ret = dlg.Show
DOpus.Output Dialog.Show returned & ret
DOpus.Output The selected choice was & dlg.choices(dlg.selection)
And this renaming scrip works as well:
' MultiRegeX OnGetNewName format_003.vbs
' 2017-06-22 RegEx OnGetNewName REWRITE
' Renamed from Scr_CreateDateTimePrefix to Scr_CreateDateTimePrefixPhotos
' To reflect specialised photo application
' Add a P suffix no space
' VBScript is necessary to extract the CreateDateTime parameter
' The rename part is done with a script but could have just been done wiht a regex
' 2018-10-07 Save Ver 029 to Laptop > Opus > 0500299 Renameing Notes > 29 Scr_CreateDateTimePrefixPhotos
'
Option explicit
Function OnGetNewName(ByRef getNewNameData)
Dim Var_RegEx_1
Dim Var_Str_Extension
Dim Var_Str_Name_Stem
Dim Str_CreateDateTime
'##############################################################################
' Extract create time
'##############################################################################
Str_CreateDateTime = getNewNameData.item.create
DOpus.Output(#############################################################)
DOpus.Output(0001000 Str_CreateDateTime BEFORE: & Str_CreateDateTime)
Str_CreateDateTime = Replace(Str_CreateDateTime,:,h,1,1)
Str_CreateDateTime = Replace(Str_CreateDateTime,:,m,1,1)
DOpus.Output(0001010 Str_CreateDateTime AFTER: & Str_CreateDateTime)
DOpus.Output(0001020 getNewNameData.newname_stem: & getNewNameData.newname_stem)
DOpus.Output(0001030 getNewNameData.newname_ext: & getNewNameData.newname_ext)
DOpus.Output(0001040 getNewNameData.newname_ext_m: & getNewNameData.newname_ext_m)
' Create a RegExp object. See http://msdn2.microsoft.com/en-us/library/ms974570.aspx
Set Var_RegEx_1 = new RegExp
Var_RegEx_1.IgnoreCase = False ' Case-sensitive matching.
Var_RegEx_1.Global = True ' All matches will be replaced, not just the first match.
' If we're renaming a file then remove the extension from the end and save it for later.
' (Item is a directory ) or (There is no period in the name I think??)
if getNewNameData.item.is_dir or 0 = InStr(getNewNameData.item.name,.) then
Var_Str_Extension =
Var_Str_Name_Stem = getNewNameData.item.name
DOpus.Output(0001200A Var_Str_Name_Stem: & getNewNameData.newname_stem)
else
'Items is not a directory and (I think) filename had a period in it
Var_Str_Extension = getNewNameData.item.ext
Var_Str_Name_Stem = getNewNameData.item.name_stem
DOpus.Output(0001200B Var_Str_Name_Stem BEFORE : & Var_Str_Name_Stem)
end if
'DOpus.Output(####################################)
DOpus.Output()
' Conver the name to lower-case.
' Var_Str_Name_Stem = LCase(Var_Str_Name_Stem)
'##############################################################################
' OneDrive Upload 2020MMDD_063544062_iOS RJ Bribie.jpg
' 123456789
' 06 - Seems to be 1600h in the afternoon
' 35 - Min 1635h
'
'##############################################################################
Str_CreateDateTime = getNewNameData.item.modify
DOpus.Output(0077-000 In case of OneDrive Create time is uploaded as modified time so...)
DOpus.Output(0077-000 Str_CreateDateTime BEFORE: & Str_CreateDateTime)
Str_CreateDateTime = Replace(Str_CreateDateTime,:,h,1,1)
Str_CreateDateTime = Replace(Str_CreateDateTime,:,m,1,1)
DOpus.Output(0077-010 Str_CreateDateTime AFTER: & Str_CreateDateTime)
DOpus.Output(0077-020 getNewNameData.newname_stem: & getNewNameData.newname_stem)
DOpus.Output(0077-030 getNewNameData.newname_ext: & getNewNameData.newname_ext)
DOpus.Output(0077-040 getNewNameData.newname_ext_m: & getNewNameData.newname_ext_m)
DOpus.Output(0078-000 -------- OneDrive---------------------------------------)
' See header notes above for OneDrive Prefix being removed
Var_RegEx_1.Pattern = \d{8}_\d{9}_iOS
DOpus.Output(0078-010 Var_RegEx_1.Pattern : & Var_RegEx_1.Pattern)
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0078-225A Var_RegEx_1.Test(Var_Str_Name_Stem) :TRUE)
' Var_Str_Name_Stem - This is the source string to be acted upon
' Filename before change typically .... (otherwise no match)
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, )
DOpus.Output(0078-230 AFTER Replace : & Var_Str_Name_Stem)
if len(Var_Str_Name_Stem) = 0 then
' No space required
else
' Add SPACE prefix
Var_Str_Name_Stem = & Var_Str_Name_Stem
DOpus.Output(0078-235 Var_Str_Name_Stem SPACE prefix added : & Var_Str_Name_Stem)
end if
'Var_Str_Name_Stem = W & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0078-240 OnGetNewName (Prefix added) : & OnGetNewName)
DOpus.Output(0078-250 Exit)
Exit Function
else
DOpus.Output(0078-225B Var_RegEx_1.Test(Var_Str_Name_Stem) :FALSE)
DOpus.Output(0078-230B Drop to next one)
end if
DOpus.Output()
'##############################################################################
' WhatsApp - 8 digits no suffix
'
'##############################################################################
' IMG_XXXX[Any suffix I might have added]
DOpus.Output(0088000 Universal Test for SPACE ---------------------------------------)
DOpus.Output(0088000 InStr(Var_Str_Name_Stem, ) : & InStr(Var_Str_Name_Stem, ))
if InStr(Var_Str_Name_Stem, ) = 0 then
DOpus.Output(0088010A No space InStr should be 0 : & InStr(Var_Str_Name_Stem, ))
Var_RegEx_1.Pattern = .*
DOpus.Output(0088220A Var_RegEx_1.Pattern >>> & Var_RegEx_1.Pattern & <<<)
else
DOpus.Output(0088010B There is a space InStr should be non zero : & InStr(Var_Str_Name_Stem, ))
Var_RegEx_1.Pattern = .*
DOpus.Output(0088220B Var_RegEx_1.Pattern Note trailing space >>> & Var_RegEx_1.Pattern & <<<)
end if
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0088225A Var_RegEx_1.Test(Var_Str_Name_Stem) :TRUE)
' Var_Str_Name_Stem - This is the source string to be acted upon
' Filename before change typically .... (otherwise no match)
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, )
DOpus.Output(0088230 AFTER Replace : & Var_Str_Name_Stem)
if len(Var_Str_Name_Stem) = 0 then
' No space required
else
' Add SPACE prefix
Var_Str_Name_Stem = & Var_Str_Name_Stem
DOpus.Output(0088235 Var_Str_Name_Stem SPACE prefix added : & Var_Str_Name_Stem)
end if
'Var_Str_Name_Stem = W & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0088240 OnGetNewName (Prefix added) : & OnGetNewName)
DOpus.Output(0088250 Exit)
Exit Function
else
DOpus.Output(0088225A Var_RegEx_1.Test(Var_Str_Name_Stem): FALSE)
end if
DOpus.Output()
'##############################################################################
' iPhone
' IMG_XXXX NO suffix
'##############################################################################
' IMG_XXXX[No suffix]
Var_RegEx_1.Pattern = (IMG_\d\d\d\d)
DOpus.Output(0001220 Var_RegEx_1.Pattern: & Var_RegEx_1.Pattern)
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0001225A Var_RegEx_1.Test(Var_Str_Name_Stem): TRUE)
' Var_Str_Name_Stem - This is the source string to be acted up
' Filename before change typically IMG_XXXX (otherwise no match)
'
' Replace whole filename with $2 suffix if it exists
' Generally there is no suffix so presumably $2 is empty
' IMG_1234 >
' IMG_1234 Blah > Blah
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, )
DOpus.Output(0001230 Var_Str_Name_Stem AFTER(Before prefix added): & Var_Str_Name_Stem)
Var_Str_Name_Stem = P & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0001240 OnGetNewName (Prefix added): & OnGetNewName)
else
DOpus.Output(0001225A Var_RegEx_1.Test(Var_Str_Name_Stem): FALSE)
end if
DOpus.Output()
'##############################################################################
' iPhone
' IMG_XXXX with suffix
'##############################################################################
' IMG_XXXX[Any suffix I might have added]
Var_RegEx_1.Pattern = (IMG_\d\d\d\d) (.*)
DOpus.Output(0001220 Var_RegEx_1.Pattern: & Var_RegEx_1.Pattern)
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0001225A Var_RegEx_1.Test(Var_Str_Name_Stem): TRUE)
' Var_Str_Name_Stem - This is the source string to be acted up
' Filename before change typically IMG_XXXX (otherwise no match)
'
' Replace whole filename with $2 suffix if it exists
' Generally there is no suffix so presumably $2 is empty
' IMG_1234 >
' IMG_1234 Blah > Blah
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, $2)
DOpus.Output(0001230 Var_Str_Name_Stem AFTER(Before prefix added): & Var_Str_Name_Stem)
Var_Str_Name_Stem = P & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0001240 OnGetNewName (Prefix added): & OnGetNewName)
else
DOpus.Output(0001225A Var_RegEx_1.Test(Var_Str_Name_Stem): FALSE)
end if
DOpus.Output()
'##############################################################################
' WhatsApp - Suffix
'
'##############################################################################
' IMG_XXXX[Any suffix I might have added]
Var_RegEx_1.Pattern = (\w+-)+(\w+)\s(.*)
DOpus.Output(0003220 Var_RegEx_1.Pattern: & Var_RegEx_1.Pattern)
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0003225A Var_RegEx_1.Test(Var_Str_Name_Stem): TRUE)
' Var_Str_Name_Stem - This is the source string to be acted up
' Filename before change typically .... (otherwise no match)
'
'
'
'
'
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, W $3)
DOpus.Output(0003230 Var_Str_Name_Stem AFTER(Before prefix added): & Var_Str_Name_Stem)
'Var_Str_Name_Stem = W & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0003240 OnGetNewName (Prefix added): & OnGetNewName)
else
DOpus.Output(0003225A Var_RegEx_1.Test(Var_Str_Name_Stem): FALSE)
end if
DOpus.Output()
'##############################################################################
' WhatsApp - No Suffix
'
'##############################################################################
' IMG_XXXX[Any suffix I might have added]
DOpus.Output(0004000 WhatsApp - No Suffix ------------------------------------------------)
Var_RegEx_1.Pattern = (\w+-)+(\w+)
DOpus.Output(0004220 Var_RegEx_1.Pattern: & Var_RegEx_1.Pattern)
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0004225A Var_RegEx_1.Test(Var_Str_Name_Stem): TRUE)
' Var_Str_Name_Stem - This is the source string to be acted up
' Filename before change typically .... (otherwise no match)
'
'
'
'
'
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, W)
DOpus.Output(0004230 Var_Str_Name_Stem AFTER(Before prefix added): & Var_Str_Name_Stem)
'Var_Str_Name_Stem = W & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0004240 OnGetNewName (Prefix added): & OnGetNewName)
Exit Function
else
DOpus.Output(0004225A Var_RegEx_1.Test(Var_Str_Name_Stem): FALSE)
end if
DOpus.Output()
'##############################################################################
' WhatsApp - 8 digits no suffix
'
'##############################################################################
' IMG_XXXX[Any suffix I might have added]
DOpus.Output(0008000 WhatsApp - 8 digits no suffix ---------------------------------------)
Var_RegEx_1.Pattern = (\w{8})
DOpus.Output(0008220 Var_RegEx_1.Pattern: & Var_RegEx_1.Pattern)
if Var_RegEx_1.Test(Var_Str_Name_Stem) = True then
DOpus.Output(0008225A Var_RegEx_1.Test(Var_Str_Name_Stem): TRUE)
' Var_Str_Name_Stem - This is the source string to be acted up
' Filename before change typically .... (otherwise no match)
'
'
'
'
'
'
Var_Str_Name_Stem = Var_RegEx_1.Replace(Var_Str_Name_Stem, W)
DOpus.Output(0008230 Var_Str_Name_Stem AFTER(Before prefix added): & Var_Str_Name_Stem)
'Var_Str_Name_Stem = W & Var_Str_Name_Stem
' CreateDateTime Prefix
' Either or Blah from RegEx above
' Restore extension
OnGetNewName= Str_CreateDateTime & Var_Str_Name_Stem & Var_Str_Extension
DOpus.Output(0008240 OnGetNewName (Prefix added): & OnGetNewName)
else
DOpus.Output(0008225A Var_RegEx_1.Test(Var_Str_Name_Stem): FALSE)
end if
DOpus.Output()
End Function
However when I put the first DOpus.dlg within the second I get wierd errors
Any comments much appreciated as always...