/*
This example demonstrates how to split a collection into 2
*/
NewScene( null, false );
// ----------------------------------------------------
// Create a collection & populate it
var oFolks = new ActiveXObject( "XSI.Collection" );
var oSammy = ActiveSceneRoot.AddNull( "Sammy" );
oFolks.Add( oSammy );
var oRoger = ActiveSceneRoot.AddNull( "Roger" );
oFolks.Add( oRoger );
var oBelinda = ActiveSceneRoot.AddNull( "Belinda" );
oFolks.Add( oBelinda );
var oAgnes = ActiveSceneRoot.AddNull( "Agnes" );
oFolks.Add( oAgnes );
// This will tell us that Sammy, Roger, Belinda, and Agnes
// are all members of the folks collection
checkContents( oFolks, "oFolks" );
Application.LogMessage( "----------------" );
// ----------------------------------------------------
// Remove Sammy and Roger and save the removed ones
// in another collection, leaving the original with the
// two women and the new collection with two men
var oMen = oFolks.RemoveItems( "Sammy,Roger" );
checkContents( oFolks, "oFolks" );
checkContents( oMen, "oMen" );
//--------------------------------------------------
function checkContents( in_coll, in_id )
{
if ( in_coll.Count > 0 )
{
LogMessage( in_id + " collection contains: " + in_coll.GetAsText() );
}
else
{
Application.LogMessage( in_id + " collection is empty." );
}
}
//--------------------------------------------------
// Output of above script:
//INFO : "oFolks collection contains: Sammy,Roger,Belinda,Agnes"
//INFO : "----------------"
//INFO : "oFolks collection contains: Belinda,Agnes"
//INFO : "oMen collection contains: Sammy,Roger" |