Quantcast
Channel: Daz Script Developer Discussion - Daz 3D Forums
Viewing all articles
Browse latest Browse all 1067

Why is this function returning null?

$
0
0

Hi,

I'm having trouble understanding why this code is not working.  Basically I load a figure into the scene and select it.

The script is then supposed to find a bone with the word "abdomen" in it's name (and then select the bone).  The function 'findBone()' appears to be working correctly,

but it keeps returning null instead of a bone.  I've been staring at it until I'm cross-eyed and I still can't see why it's doing this:

(function() {
	var title = "Select Child Nodes",
			node = null,
			skel = null;
	
	// Find a bone containing 'str' in it's name:
	function findBone(parent, str) {
		var len = parent.getNumNodeChildren(),
			child = null;
		
		for (var i=0; i<len; i++) {
			child = parent.getNodeChild(i);
			print("Checking: "+child.getName());
			
			if (child.getName().find(str) >= 0) {
				print(child.getName() + " found!");
				return child;
			}
		
			findBone(child, str);
		}
	}
	
	try {	
		node = Scene.getPrimarySelection();
		
		if (!node)
			throw new Error("Select a bone in a figure");
		
		if (node.inherits("DzSkeleton"))
			skel = node;
		else if (node.inherits("DzBone"))
			skel = node.getSkeleton();
		else
			throw new Error("Select a bone in a figure");		

		var abdomen = findBone(skel, "abdomen");
		if (abdomen)
		  abdomen.select(true);
		else
			print("Bone Not Found!");
	}
	catch(err) {
		MessageBox.critical(err.message + "\n(line: " + err.lineNumber + ")",
												title, "&OK" );
		return false;
	}
})()

 


Viewing all articles
Browse latest Browse all 1067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>