Sorry it's not vb and it does just what peter said
var inObjectsColl = XSIFactory.CreateActiveXObject( "XSI.Collection" );
inObjectsColl.AddItems( SortedCollection( inParentName,
inFilterString ) );
function sortByName(a, b) {
var x = a.Name.toLowerCase();
var y = b.Name.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function SortedCollection(inParentName, inFilterString)
{
var parent=Dictionary.GetObject(inParentName);
var inObjectsColl = XSIFactory.CreateActiveXObject( "XSI.Collection" );
inObjectsColl.AddItems( parent.FindChildren( inFilterString ) );
var sortArray = new Array();
for(var i=0; i<inObjectsColl.Count; i++)
{
sortArray[i]=inObjectsColl.Item(i);
}
sortArray.sort( sortByName );
inObjectsColl.RemoveAll();
for(var i=0; i<sortArray.length; i++)
{
inObjectsColl.Add(sortArray[i]);
}
return inObjectsColl;
}
peter boeykens wrote:
I thought a collection was an array, but Im probably wrong.
perhaps if you first declare the array, and then simply equal the
array to the collection it could work
something like:
myArray = Array()
and then later on in the script
myArray = oCollection
If that doesnt do it, then you can loop through you collection and add
each item into the array.
something like:
for i = 0 to oCollection.count
set myArray(i) = oCollection(i)
next
If it doesnt crap out, you would end up with an array containing your
objects.
I dont know about the quicksort, but I would expect it to require
strings, in which case, rather than storing the items in the array,
you would have to store their name.
probably like this: myArray(i)=oCollection(i).name
Sorry for the newbie scripting advice, and if it explodes, it wasnt me!
----- Original Message -----
*From:* Adam Seeley <mailto:Adam.Seeley(at)primefocusworld.com>
*To:* XSI(at)Softimage.COM <mailto:XSI(at)Softimage.COM>
*Sent:* Wednesday, October 17, 2007 7:32 PM
*Subject:* RE: Scripting - Sorting a Collection
Soz,
VB Script at the moment.
A.
------------------------------------------------------------------------
*From:* owner-xsi(at)Softimage.COM
<mailto:owner-xsi(at)Softimage.COM>
[mailto:owner-xsi(at)Softimage.COM] *On Behalf Of *Adam Seeley
*Sent:* 17 October 2007 18:30
*To:* XSI(at)Softimage.COM <mailto:XSI(at)Softimage.COM>
*Subject:* Scripting - Sorting a Collection
Hi,
I've pulled all the Passes in a Scene into a collection and
now I want to Output information to a text file or Excel sheet.
The default order of the Collection seems to be the Creation
order, but I would like to output the information in the same
order as the Alphanumeric sort that I see in the Explorer.
There is the Quicksort function which I could use. This seems
to mean that I have put the collection into an Array to sort
it first.
I can make the array ok but is there a way to easily sort the
Collection instead, otherwise are there any commands lying
around that would pipe the Collection Sstraight into an array
(and back). Seems like the kind of function that would exist
already somewhere.
Many thanks,
Adam.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security
System.
For more information please visit
http://www.messagelabs.com/email
______________________________________________________________________
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.12 - Release Date:
15/10/2007 00:00
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.12 - Release Date:
15/10/2007 00:00
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.12 - Release Date:
15/10/2007 00:00
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi