Checking if an ICE node is part of a connected branch


Here’s a little recursive function that checks whether the selected ICE node is part of a branch that is connected to the terminal ICE Tree node.

I used IsConnected to check whether a node is connected to some other node, and then I traverse the output ports, getting the connected nodes, until I reach the ICE Tree node (or not).

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


// Given an ICE node, check if the node is part
// of a branch connected to the ICE Tree node
function isBranchConnected( oNode )
{
	if ( !oNode.IsConnected )
	{
		return false;
	}
	else if ( oNode.Type == "ICETree" )
	{
		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 isBranchConnected( oSelItem1 );
			}
		}
	}
}

And here’s a Python version. With Python, I always have the nagging feeling that my code code be better.

# Given an ICE node, check if the node is part
# of a branch connected to the ICE Tree node
def isBranchConnected( oNode ):
	if not oNode.IsConnected : 
		return False
	elif oNode.Type == "ICETree" :
		return True;
	else:
		for port in oNode.OutputPorts:
			for node in port.ConnectedNodes:
				return isBranchConnected( node )



o = Application.Selection(0);
Application.LogMessage( "isBranchConnected()=" + str(isBranchConnected(o)) );

1 thought on “Checking if an ICE node is part of a connected branch

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s