Script to consolidate GetData nodes

Discussions about SOFTIMAGEs© Interactive Creative Environment©
Eric Cosky
Posts: 18
Joined: 27 Aug 2009, 17:31

Script to consolidate GetData nodes

Post by Eric Cosky » 11 Jan 2012, 20:43

The script below will scan all GetData nodes of the currently selected ICE tree and will connect the "In Name" ports to any GetData nodes that refer to a model whose "Out Name" will match the prefix of the "In Name" ports, trimming the item name down to include only the part unique to the node.

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


User avatar
rray
Moderator
Posts: 1810
Joined: 26 Sep 2009, 13:51
Location: Bonn, Germany

Re: Script to consolidate GetData nodes

Post by rray » 11 Jan 2012, 21:59

Thanks for sharing - If not using BVH this can easily be adapted for different situations.
softimage resources section updated Sep 26th 2026