ICE Tree traversal - [solved]

Discussions concerning programming of SOFTIMAGE©
User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

ICE Tree traversal - [solved]

Post by Hirazi Blue » 19 May 2011, 08:04

I was trying to do some Pythonesk traversal of an ICE Tree using a slight adaptation of this script. This works, but doesn't seem to take into account the difference between nodes that are part of a branch that is connected to the ICE Tree node and nodes that are just laying in the ICE Tree View doing nothing. So now my question is, working from any given node, what would be the easiest way to test if it's part of a connected branch or not?
:-\
Stay safe, sane & healthy!

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: ICE Tree traversal - unconnected branches

Post by xsisupport » 19 May 2011, 11:17

ICENode.IsConnected ?
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: ICE Tree traversal - unconnected branches

Post by Hirazi Blue » 19 May 2011, 14:19

No, that doesn't get me the result I was looking for exactly, as this returns "True" for nodes in a branch that itself isn't connected to the ICE Tree, if they themselves are connected to another node in such a disconnected branch... Only the node that is/isn't actually connected to the ICE Tree gives the correct result. It does work as a further adaptation of the aforementioned script, as I can use it to "prune" the tree, but my question goes further than that...
So maybe my example (and the title of this thread) was wrong :ymblushing: , as (for what I ultimately want to achieve) I do not want to necessarily start at the root of the ICE Tree, but at any single node in the ICE Tree View.
I'm probably just barking up the wrong tree here (pun intended), but I'm looking for a way to select a single node and decide quickly in a script if it's part of (as in: connected to) the current ICE Tree or merely taking up space in the ICE Tree View, waiting for better times...
;)
Stay safe, sane & healthy!

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: ICE Tree traversal - unconnected branches

Post by xsisupport » 19 May 2011, 16:00

I think you'll have to traverse the output ports, checking IsConnected.
To test this snippet, select an ice node in the explorer.

Code: Select all

var o = Selection(0);
//LogMessage( o.IsConnected );
LogMessage( "test()="+test(o) );

function test( oNode )
{
	if ( !oNode.IsConnected )
	{
		LogMessage( "Not connected" );
		return false;
	}
	else if ( oNode.Type == "ICETree" )
	{
		LogMessage( "Connected" );
		return true;
	}
	else
	{
		oEnum = new Enumerator( oNode.OutputPorts ) ;
		for (;!oEnum.atEnd();oEnum.moveNext() )
		{
			var oSelItem = oEnum.item() ;
			oEnum1 = new Enumerator( oSelItem.ConnectedNodes ) ;
			for (;!oEnum1.atEnd();oEnum1.moveNext() )
			{
				var oSelItem1 = oEnum1.item() ;
				return test( oSelItem1 );
			}
		}
	}
}
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: ICE Tree traversal - unconnected branches

Post by Hirazi Blue » 19 May 2011, 17:37

Ah, I guess I was truly barking up the wrong (side of the) tree...
Thanks, I will check this out :-bd
Stay safe, sane & healthy!

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: ICE Tree traversal - unconnected branches

Post by Hirazi Blue » 20 May 2011, 17:42

repost/edit: I removed the very preliminary resulting plugin from this thread... ;)
Stay safe, sane & healthy!

Leo
Posts: 128
Joined: 04 Jun 2009, 15:06

Re: ICE Tree traversal - unconnected branches

Post by Leo » 20 May 2011, 17:57

Don't be so insecure about your work, just post what you got, it was working fine wasn't it?