Clear as mud I'm sure so here's the real world situation that caused me to write this:
* Import a BVH to the scene. In the model named after the bvh filename, you'll see a slew of nodes in a group called "bvhfilename_Animated_Objects"
* Create a point cloud, and add an ICE tree to it.
* Drag all the items in the Animated_Objects group into the ICE tree. There are now a bunch of nodes called "Get bvhfilename.Hips", etc, all standalone nodes pointing to "bvhfilename." + the specific item in the model.
* Create a GetData node and pick the bvh model.
* Select the ICE tree in the explorer and run the script. Once it finishes you will see how all the get data nodes that used to be (for example) "bvhfilename.Hips" now have "In Name" connected to the "Out Name" of the "bvhfilename" node, and the names have been shortened to (for example) ".Hips".
The script is released under the terms of the CC BY 3.0 license http://creativecommons.org/licenses/by/3.0/.
I hope someone finds this useful.
Code: Select all
function CreateNameNode(names, nameNodes, node)
'logmessage node.Fullname
'logmessage typename (node)
if(typename(node) <> "ICEDataProviderNode") then
'logmessage "Create skipping " & node & " type:" & typename(node)
exit function
end if
dim prop
'set prop = Dictionary.GetObject(node & ".reference")
set prop = Dictionary.GetObject( node.FullName & ".reference")
'logmessage "Create: " & prop
refname = GetValue(prop)
'logmessage inname
for i = 0 to nameNodes.Count - 1
if names(i) = refname then
exit function
end if
next
'logmessage parent
logmessage "GetData node: " & refname
names.Add(refname)
namenodes.Add(node)
end function
function ConsolidateNameNode(names, nameNodes, node)
if(typename(node) <> "ICEDataProviderNode") then
exit function
end if
dim prop
isconnected = node.InputPorts("inname").IsConnected
'logmessage "Cons: " & isconnected
if(isconnected) then
exit function
end if
set prop = Dictionary.GetObject( node.FullName & ".reference")
refname = GetValue(prop)
logmessage "Consolidate: " & prop & " = " & refname & " type:" & typename(refname)
' Get the parent of the current GetData reference, and see if there is a node we can use
' the OutName port from instead of the full path.
dim refparent, ref
set ref = Dictionary.GetObject(refname)
set refparent = ref.model
logmessage "Consolidate Ref:" & ref
logmessage "Consolidate RefParent:" & refparent
'logmessage inname
for i = 0 to names.Count - 1
if names(i) = refparent then
logmessage "Node " & ref & " found parent " & refparent
ConnectICENodes node.Fullname & ".inname", nameNodes(i).Fullname & ".outname"
node.reference = Right(refname, len(refname) - len(refparent))
exit function
end if
next
end function
function ConsolidateGetDataNodes
dim node
dim nameNodes
Set nameNodes = CreateObject("System.Collections.ArrayList")
dim names
Set names = CreateObject("System.Collections.ArrayList")
dim n
dim refNodes
set refnodes = selection(0).Nodes
logmessage "Node count: " & refnodes.count
for each n in refnodes
CreateNameNode names, nameNodes, n
next
for each n in refnodes
ConsolidateNameNode names, nameNodes, n
next
end function
ConsolidateGetDataNodes