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)) );
Thanks (especially also for the Python version) 😉