NoteWorthy Composer Forum

Forums => Tips & Tricks => User Tools => Topic started by: NoteWorthy Online on 2006-04-26 05:16 pm

Title: Getting started with NWC2 User Tools
Post by: NoteWorthy Online on 2006-04-26 05:16 pm
NoteWorthy Composer 2 includes a new User Tool facility.


Some facts about the User Tool facility:


If you are already using NWC2, then the easiest way to get started with the User Tool facility is by downloading and installing the NWC2 User Tool Starter Kit (http://ntworthy.com/nwc2/usertools/). It will automatically detect your existing copy of NWC2 and setup a set of scripts for immediate use.

The starter kit includes the following tools:


The starter kit also includes the following scripts from Andrew Purdam:

Title: Using prompts when invoking a User Tool
Post by: NoteWorthy Online on 2006-04-27 09:00 am
This example demonstrates prompting for data before invoking a User Tool.

The actual tool script looks like this:

Code: (nwsw_PromptExample.php) [Select · Download]
<?php
// nwsw_PromptExample.php Version 1.0
//
// This script demonstrates the prompting mechanism in NWC2 User Tools.
//
// Copyright © 2004 by NoteWorthy Software, Inc.
// All Rights Reserved
//
// History:
// 2004-12-12: Initial release (1.0)
//
require_once("lib/nwc2clips.inc");

$clip = new NWC2Clip('php://stdin');

$raw_argv = print_r($argv,true);

echo <<<___EOTEXT
This script demonstrates one method for passing command line
arguments into a user tool. This demonstration accepts three
options, each of which are prompted on the scripts behalf
by NWC2.

The built-in argc and argv variables are set as follows:
\$argc = $argc
\$argv = $raw_argv

The result of the example processing of the options is
shown below. To see how this was done, simply look at
the source for this script.

___EOTEXT;

// Below is an example of one technique for evaluating the arguments passed
// to the script
$opts = array();
foreach ($argv as $k => $v) {
  if (!$k) continue;

  if (preg_match('/^\/(opt[1-3])\=(.*)$/',$v,$m)) {
    $optname = $m[1];
    $optvalue = $m[2];
    $opts[$optname] = $optvalue;
    }
  }

if (isset($opts["opt1"])) {
  echo "\nOption 1 is set with the following data: $opts[opt1]\n";
  }

if (isset($opts["opt2"])) {
  echo "\nOption 2 is set with the following data: $opts[opt2]\n";
  }

if (isset($opts["opt3"])) {
  echo "\nOption 3 is set with the following data: $opts[opt3]\n";
  }

exit(NWC2RC_REPORT);
?>

The Command used in the NWC2 User Tool Description is as follows:

Code: [Select · Download]
'php\php.exe scripts\nwsw_PromptExample.php "/opt1=<PROMPT:Prompt 1: Select an option from this list:=|Quarter|8th|16th|32nd>" "/opt2=<PROMPT:Prompt 2: Enter a number=#[0,15]>" "/opt3=<PROMPT:Prompt3: Enter some text=*>"'
Title: Backing up your script commands (Re: Getting started with NWC2 User Tools)
Post by: Ertuğrul İnanç on 2006-05-12 10:14 am
 
I was going to ask this but discovered myself (aint I smart? :D) and wanted to share:

So you have quite a few user tool scripts with various parametres stored under your Tools > User Tool... dialogue as I do? Probably you'd like to to make a backup of them now and then. But how? So simple.

They are stored in a plain text file named nwc2UserTools.ini under the directory defined in Tools > Options > Folders > Config Files, which is by default \NoteWorthy Composer 2\Config.

Backup that file. :)

PS: Thanks Eric, updated per your post (https://forum.noteworthycomposer.com/?topic=5537.msg36107#msg36107)!
 
Title: Re: Getting started with NWC2 User Tools
Post by: NoteWorthy Online on 2006-05-12 10:21 am
More precisely, the User Tool setttings are stored in the folder located by Tools, Options, Folders, Config Files.
Title: Re: Getting started with NWC2 User Tools
Post by: NoteWorthy Online on 2006-05-13 12:37 pm
Version 1.13 of the NWC2 User Tool Starter Kit (http://ntworthy.com/nwc2/usertools/) has now been released. It includes minor updates to many of the scripts.
Title: Re: Getting started with NWC2 User Tools
Post by: eupher61 on 2006-12-04 11:55 pm
So...I'm trying to download the User Tools, v1.21, and it tells me my NWC is either not installed or has been altered since installation. 
Duh...I've kept up with the updates to the 2.x beta.

It's not a Firefox issue, I've tried IE and Firefox both.  Is there something else I'm missing somewhere??

HELP!

steve
Title: Re: Getting started with NWC2 User Tools
Post by: NoteWorthy Online on 2006-12-05 12:47 am
This error means that the NWC2 uninstall information does not point to the correct NWC2 program files location. There are two possible causes for this (assuming you actually have NWC2 installed):


You can correct this by reinstalling NWC2 or by manually correcting the folder paths found in the following registry area:

Code: [Select · Download]
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NoteWorthy Composer 2
Title: Comments
Post by: adge on 2008-12-30 04:11 pm
Can I put comments into a clip text file? It would help diagnosis a lot. And what happens to SYSERR if the script completes OK?
Title: Re: Comments
Post by: NoteWorthy Online on 2008-12-30 05:35 pm
Here are some links that might help:

Title: Re: Comments
Post by: Rick G. on 2008-12-30 05:56 pm
Can I put comments into a clip text file?
Yes. They will display in the STDOUT popup, but they are discarded when STDOUT is parsed back into the song.
Some further discussion <here> (https://forum.noteworthycomposer.com/?topic=6246.msg42086#msg42086).

what happens to SYSERR if the script completes OK?
If the script completes OK, there can be no SYSERR. One shouldn't care about what happens to it.
Title: Re: Comments
Post by: adge on 2009-01-01 04:56 pm
Noteworthy Online - Thank you; I should have found this; I am an idiot; thank you for not telling me so.

Rick G - You are a better coder than me. I often find that the script finishes, but produces something different from what I expected. Without some means of monitoring flow and checking values of variables it is hard to find the bug. Thank you, though.

Title: Re: Comments
Post by: Rick G. on 2009-01-01 06:25 pm
Without some means of monitoring flow and checking values of variables it is hard to find the bug. Thank you, though.
If you are coding in JScript or VBScript, I may be able to help.

Put WScript.Quit(99) where your program ends. This will cause NWC2 to display STDOUT to you (comments and all). Comment out the line or change it to: WScript.Quit(0) to test normal operation.

In JScript, I declare an array (e.g., var a = [];) and push things I'm interested in on to it.
At program end, I use: WScript.Echo(a.join("\n"));
Title: Re: Getting started with NWC2 User Tools
Post by: Randy Williams on 2010-11-10 08:06 pm
One possible use of the new "Run User Tool" tool is to aid in new user tool testing/debugging.

If you run your new clip script via the "RUT" tool, and you check the box to "Display summary of changes, if user tool returns success", then you will see a NWCTXT "delta" of the changes that your script made.  The delta for each staff is shown in turn separately.  At any point, you can make "backdoor" changes to your script, then do a "back" and a "next" in RUT, and see the new results of your script, all without leaving the RUT environment.  Once happy with the changes, you can proceed out of RUT and see your changes applied within NWC2.

The RUT user tool entry to invoke your new user tool could have a command like this:
php\php.exe scripts\prw_RunUserTool.wxphp display all "<yourtoolname>"

The display pre-checks the box to display summaries of changes, and the all says to do all staffs in turn.  Make sure to set an "Input Type" of "File Text", and check the options "Returns File Text" and "Prompts for User Input".
Title: Re: Getting started with NWC2 User Tools
Post by: aardvarksong1 on 2012-11-08 06:20 pm
I am trying to create tool that allows the user to enter a specific entity such as an instrument change, clef, dynamic or barline at the current cursor position. I looked at the examples in the User Tools and they all seem to apply changes to the entire file, or a selection of notes. Is there any way of inserting a specific entity at the cursor position?
Title: Re: Getting started with NWC2 User Tools
Post by: Rick G. on 2012-11-08 07:32 pm
Is there any way of inserting a specific entity at the cursor position?
It is possible by requiring File text and returning File text. NWC will prompt you to save your work since the change cannot be undone :(

More discussion at: Insert entity at current cursor position working example (https://forum.noteworthycomposer.com/?topic=8312.0).