Re: Script : Collection freeze selection.

Date : Mon, 3 Oct 2005 09:17:50 +0200
To : XSI(at)Softimage.COM
From : guillaume laforge <guillaume.laforge.3d(at)gmail.com>
Subject : Re: Script : Collection freeze selection.
Thanks a lot Bernard.
 
You're right, adding collection to a collection is not the easiest way. "Additems" is the solution.
All your advise will be helpful !
 
Cheers,
 
Guillaume

 
2005/10/2, Bernard Lebel <3dbernard(at)gmail.com>:
I noticed something. I inserted a little loop that prints the content
of oKind, and I get nothing, only a blank line, and only one item was
printed. Then when the selection command runs, it says it is selecting
the objects under the model. At that point, nothing is appears
selected, but indeed I can't select anything. If I right-click on the
model and choose Lock Infos, then the model shows up as selected.


Anyway I rewrote your script and it works fine.

First, instead of creating the model collection in the global scope
and populating it in-place from a function, I create it directly in
the function and returns it to a variable (should also make your code
faster on larger scenes).

Second, I take extra steps to test collection counts, so if the count
is 0, nothing else happens.

Finally, notice the mofication I made with the findchildren call. I
suspect one of the problems of your script might be caused by the fact
that you used add() instead of additems(), so you were adding
collections (returned by findchildren()) instead of geometry. Remember
that add() works better with single element.

Here is the code:


// Get valid models
var oModels = FindKind( "Character" );

// Test if valid models were found.
if( oModels.count > 0 )
{
       // Create collection to store valid meshes under valid models
       var oMeshes = XSIFactory.CreateObject( "XSI.Collection" );

       // Collect polygon meshes under valid models
       for( var e = new Enumerator( oModels ); !e.atEnd(); e.moveNext() )
       {
               oMeshes.additems( e.item().findchildren( "", siPolyMeshType, null, true ) );
       }

       // Test if polygon meshes were found, if so, select them
       if( oMeshes.count > 0 )
       {
               selectobj( oMeshes );
       }
}



function FindKind( sKind )
{
       // Create collection to store valid models
       var oAllModels = XSIFactory.CreateObject( " XSI.Collection" );

       // Iterate all models
       for( var oAllModelsEnum = new Enumerator( activesceneroot.models );
!oAllModelsEnum.atEnd(); oAllModelsEnum.moveNext() )
       {
               var oCpset = oAllModelsEnum.item().properties( sKind );
               if( oCpset )
               {
                       oAllModels.add( oAllModelsEnum.item() );
               }
       }

       return( oAllModels );
}




> PS : Sorry for the bad formatting in the script. I must instal firefox on my
> laptop someday. IE is not very friendly with Gmail :-/

That has nothing to do with IE. Firefox also mangles the code formatting.


Cheers
Bernard

---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.