// Copyright (C) 1997-2004 Alias Systems Corp.
// 
// The information in this file is provided for the exclusive use of the
// licensees of Alias.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias license agreement, without fee.
// 
// ALIAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

//
//  Alias Script File
//  MODIFY THIS AT YOUR OWN RISK
//
//  Creation Date:  Oct, 1999
//
//	Procedure Name:
//		doEditCharacterArgList
//
//	Description:
//		Edit the character
//
//	Input Arguments:
//	$version: The version of this option box.  Used to know how to 
//	interpret the $args array.
//		"1" : first verison of nla
//  
//	$args
//	Version 1
//	[0]		$editMode :  how to edit the character
// 			0 == Remove selected channel box attrs from character
// 			1 == Add select channel box attrs to character
//
//	Return Value:
//		$string: The command string
//


global proc
doEditCharacterArgList( string $version, string $args[] )
{
	string $editMode        = $args[0];
	
	// Is a character selected?
	//
    string $sel[]    = `ls -sl -type character`;

	// If no character selected, see if there is a current character
	//
	if (0 == size($sel)) {
		$sel = `currentCharacters`;
	}

	if (size($sel) == 0) {
	    error "Must have a current character or select a character.";
		return;
	}

	// Find what is selected in the channel box
	//
	string $attrs[] = `selectedChannelBoxPlugs`;
	if (0 == size($attrs)) {
		error "No attributes are selected in the channel box.";
		return;
	}

	// Build the command string
	//
	string $cmdAttrs;
	for ($attr in $attrs) {
		// Is the attribute on the character node? If so, translate it
		// to the corresponding member attribute.
		//
		string $buff[];
		tokenize($attr,".",$buff);
		if (nodeType($buff[0]) == "character") {
			string $conns[] = `listConnections -s 0 -d 1 -p true $attr`;
			if (size($conns)) {
				$attr = $conns[0];
			}
		}
		
		$cmdAttrs += $attr;
		$cmdAttrs += " ";
	}

	for ($character in $sel) {
		string $cmdString = ("character ");
		if (0 == $editMode) {
			$cmdString += "-rm ";
		} else {
			$cmdString += "-forceElement ";
		}
		$cmdString += ($character+" "+$cmdAttrs);
		evalEcho $cmdString;
	}
}
