Adding a new Internal Command
This is an example of a script add-in that adds a new internal command to Opus.
This command, SelectNewest, selects one or more of the newest files in the current folder. You would use this by creating a new .js file in the Script Addins folder (type /dopusdata/Script Addins into the location field to find this).
You could then create a button or hotkey to run the SelectNewest command just like any other internal Opus command.
The basic procedure to add an internal command from a script add-in is:
Either:
In the OnInit event, create a ScriptCommand object with the ScriptInitData.AddCommand method.
Or, in the OnAddCommands event, create a ScriptCommand object with the AddCmdData.AddCommand method.
Initialize the properties of the ScriptCommand object. At a minimum you must populate the name and method properties.
Create a separate function in your script-add in, with the method name you specified for the command. This will be your command's entry point.
// Set the script type to JScript to use this script. // The OnInit function is called by Directory Opus to initialize the script add-in. function OnInit(initData) { // Provide basic information about the script by initializing the properties of the ScriptInitData object. initData.name = "Select Newest Files"; initData.desc = "Select the newest X files in the folder"; initData.copyright = "(c) 2016 Jonathan Potter"; initData.default_enable = true;
}
// Implement the SelectNewest command (this entry point is an OnScriptCommand event). // The name of this function must correspond to the value specified for the method property when the command was added in OnInit. function OnSelectNewest(scriptCmdData) { // scriptCmdData is a ScriptCommandData object, and it provides the raw command-line and a Func object. // The Func object contains an Args object, which in turn contains our parsed arguments (if any), usually preferable to using the raw command-line. // We use the got_arg object to test if an argument was provided, before reading its value.
}
最后更新于