adamlaw
December 18, 2014, 6:30pm
1
I am trying to do a rename in vbscript with a button and keep the renamed files selected. I can't seem to do this
@nodeselect
@script vbscript
Option Explicit
Function OnClick(ByRef ClickData)
Dim vs_pattern
Dim vs_date
Dim Count
Dim file
Dim strNewName
Dim vs_1
vs_pattern = "(.*)"
vs_date= Now()
vs_date = Year(vs_date) & "" & Right("0" & Month(vs_date),2) & "" & Right("0" & Day(vs_date),2) & "_" & "\1"
vs_1 = "Rename PATTERN " + Chr(34) + vs_pattern + Chr(34) + " To " + Chr(34) + vs_date + Chr(34) + " REGEXP "
DOpus.output vs_1
ClickData.func.command.RunCommand vs_1
'For Each file In ClickData.func.sourcetab.selected_files
'
'strNewName = RegExReplace(file.name, vs_pattern, vs_date,True,True,True)
'DOpus.output file.name
'DOpus.output vs_pattern
'DOpus.output vs_date
'DOpus.output strNewName
'Next
End Function
Function RegExReplace(strString, strPattern, strReplace, wglobal, wignorecase, vb_multiline)
'On Error Resume Next
Dim RegEx
Set RegEx = New RegExp ' Create regular expression.
RegEx.IgnoreCase = wignorecase ' Make case insensitive.
RegEx.MultiLine = vb_multiline
RegEx.Global = wglobal 'Search the entire String
RegEx.Pattern = strPattern
If RegEx.Test(strString) Then 'Test if match is made 'RegEx.Test(strString)
RegExReplace = RegEx.Replace(strString, strReplace) ' Make replacement.
Else
'return original string
RegExReplace = strString
End If
End Function
adamlaw
December 18, 2014, 6:43pm
2
I have tried.
vs_pattern = "(.*)"
vs_date= Now()
vs_date = Year(vs_date) & "" & Right("0" & Month(vs_date),2) & "" & Right("0" & Day(vs_date),2) & "_" & "\1"
vs_1 = "Rename PATTERN " + Chr(34) + vs_pattern + Chr(34) + " To " + Chr(34) + vs_date + Chr(34) + " REGEXP "
DOpus.output vs_1
Set vo_comm = DOpus.create.command 'ClickData.func.command
vo_comm.Addline "@nodeselect"
vo_comm.Addline vs_1
vo_comm.Run
Jon
December 18, 2014, 6:49pm
3
You need to set the deselect property on the Command object you get passed:
ClickData.func.command.deselect = False
Hi, I'm sorry to drag up such and old topic, but I am doing this exactly.
I want to set the deselect options to true or false depending on the existence of the @nodeselect modifier.
Is this possible?
Thanks
Leo
January 15, 2019, 3:29am
5
Scripts don't usually use/need @nodeselect ; they can set the Command object property which Jon mentioned.
At least for scripts that are run directly via buttons.
Are you doing something else, e.g. a script which adds a command, where the command is then placed in a button instead of the script itself?
Yes.
I have created a custom command "COPYFILESIZE" which I can assign to buttons, menu, toolbars, and run from the '>' prompt
When run from a button, I want the @nodeselect option to take effect, however it doesn't seem to. because the 'clickdata.func.command' objected uses a local 'deselect' property which is true by default.
The two obvious options are to include @modifiers somewhere in the clickData object, or have the default 'clickdata.func.command' set the deselect to true or false depending on the existence of '@nodeselect '.
I don't like the second option due to the number of scripts it will likely break...
Leo
January 15, 2019, 5:09am
7
Valid point. I agree, having it available on the clickData or Func objects probably makes sense.
For now, I think the best you can do is add a DESELECT or NODESELECT argument to the command to tell it what to do.
Good call. I'll add that.
Jon
January 17, 2019, 5:16am
9
In the next update we'll add a Command.GetModifiers method that will let you query the modifiers that have been set.
1 Like