Can DOpus/dlg appear within an OnGetNewName event?

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

Yes, but the dialog will be called for every file in the list. Is that what you want?

Why don't you use custom fields?

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Custom_Fields_in_the_Rename_Dialog.htm

No I see your point I don't want the dialog called for every file.
Custom fields look interesting I will read up on them
Thanks.....

From what I understand a custom field is a way by which "Opus 12 rename scripts can add their own fields to the rename dialog itself, by implementing the OnGetCustomFields method"

This is not what I want.
What I want is the following.
Presently I have a hotkey which brings up a dialog box by which I can add a suffix to the name of all selected files:

@set SuffiXXX={dlgstring|SuffiXXX}
rename IGNOREEXT PATTERN * TO * {$SuffiXXX}
Clipboard SET {$SuffiXXX}

I want to extend this so that I have a choice of

  • A text field as above; OR
  • A pulldown menu with several predefined suffixes to choose from

This way I can prepopulate the pull down menu which suffixes that most commonly use.

I guess the first question is, would a scripting solution be required for that?
I cant see an internal command solution.
Then assuming scripting is required, I should understand better what the best option might be within that flexible (and complex) world.....

The quickest solution is to have two buttons/hotkeys, one with {dlgstring} and the other one with {dlgchoose} for the dropdown list.

To combine the two dialogs into one you would need to set up a button with that dialog and call the rename functions from there.

I'd go with the first option, the second seems too much effort for too little gain.

1 Like

Thx @lxp
Much appreciated.
I did not realise there was a {dlgchoose} option
I am short on spare keyboard shortcuts and this would need two.
Still the scripting is quite daunting for me.
Thanks....