Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / Adding components to selection using Object Model
  RSS 2.0 ATOM  

Adding components to selection using Object Model
Rate this thread
 
30182
 
Permlink of this thread  
avatar
  • Total Posts: 6
  • Joined: 03 September 2008 07:17 AM

A beginner question…

I wanted to write a quick script to convert my poly selection to edge selection (just the outline edges), something i’ve used in Modo and was not able to find in XSI.

So I wrote this in Python. I could get the current selection using the Object Model but then I add to switch back to using command to actually do the selection. I could not figure out what would be the way to add components to the selection using objects. I wonder if someone could give me some hint?

Thanks!

Claude

BTW here is the code:

[FONT=Courier New]edgeCount = {}
for poly in Application.Selection[0].SubComponent.ComponentCollection:
__for edge in poly.Edges:
____currentCount = edgeCount.get( edge.Index, 0 )
____currentCount = currentCount + 1
____edgeCount[ edge.Index ] = currentCount
itemSel = “”;
for item in edgeCount.items():
__if ( item[ 1 ] == 1 ):
____if ( len( itemSel) > 0 ):
______itemSel = itemSel + “, “
____itemSel = itemSel + repr( item[ 0 ] )
# should use Object Model rather than Command, but how?
Application.AddToSelection( Application.Selection[0].Name + “.edge[” + itemSel + “]” )
Application.SetSelFilter("Edge")
[/FONT]



Replies: 0
avatar
  • mantom
  • Posted: 08 April 2009 01:38 PM

there are several ways to do this, no one way is the blanket solution over another.

To add to an existing item to the selection use:

Selection.AddoItem );


this assumes the added item is an object of the same class as the items already in the selection. That is, if the selection contains X3Dobjects, the added item is also an X3Dobject. If the selection contains edges, then the added item should be an edge. XSI is forgiving in certain situations, so this isn’t a hard rule. But it’s best to match added types with the selection types.

Another approach is to get an XSI Collection, populate it with your edges, then pass the collection to the selection object:

var oCollection XSIFactory.CreateActiveXObject"XSI.Collection" );
oCollection.Unique true;
 
oCollection.AddoEdge );
(or)
oCollection.AddItemsoEdges );
 
Selection.AddoCollection );
(or)
Selection.SetAsTextoCollection );


Another solution:

oCollection.Items "objectname.edge[12],objectname.edge[15-19]";
 
if ( 
oCollection.Count {
   Selection
.AddoCollection );
}


the benefit to this method is oCollection will not throw an error if .Items evaluates to nothing. More useful for objects/models than components.

If working with components specifically, you might be better off using SelectGeometryComponents() command. Build your list of edges using an XSI collection and/or filtering commands, then pass the collection to the SelectGeometryComponents command. This is faster than recursively updating the selection with each new edge you encounter.


matt



Replies: 0
avatar

Thanks Matt!

So I played with it, I can just indeed add each edge as I find it using Application.Selection.Add( edge ). Works great.

Now for the more efficient way to add them all in one go, I instantiate an XSI Collection, puts all the edges in there and add the collection to the selection if not empty. But I have an error:

coll = win32com.client.Dispatch( “XSI.Collection” )
...
Application.Selection.Add( coll )

Error:
# File “<COMObject <unknown>>”, line 3, in Add
# COM Error: Interface not supported. - [line 15]

Maybe more a Python issue than anything else…

Claude



Replies: 0
avatar
  • mantom
  • Posted: 08 April 2009 02:14 PM

Oops, my fault.

Selection.Add() expects a single object.  Attempting to add an XSI Collection is like adding multiple objects in one shot.  In this case you’ll probably need to use Selection.SetAsText(), or the SelectGeometryComponents() command.

sorry,

Matt



Replies: 0
avatar

All right, that explains it then. Thanks for all the help!

Claude



Replies: 0