Tasks/TraversingRelationConstraint.py

# Copyright 2010 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# This sample shows you how to traverse animation node connections in a relation constraint.
#
# Sample scene file this script works with: traversingRelationConstraint.fbx 
# 
# Topic: FBConstraintRelation, FBAnimationNode

from pyfbsdk import *

lCons = FBSystem().Scene.Constraints
#Going through the constraints in the scene
print "********************************************"
print "***These are the constraints in the scene***"
print "********************************************"
for lCon in lCons:   
    print "Constraint Name ->", lCon.Name

print    
for lCon in lCons:   
    if lCon.Is( FBConstraintRelation_TypeInfo() ):
        print "*************************************************"
        print "***These are the %d boxes in the %s Constraint***" % (len(lCon.Boxes), lCon.Name)
        print "*************************************************"
        for lBox in lCon.Boxes:
            lOut = 0
            lIn = 0
            lAnimationNodesOUT = lBox.AnimationNodeOutGet().Nodes
            for lAnimationNode in lAnimationNodesOUT:
                for i in range(lAnimationNode.GetDstCount()):
                    if lAnimationNode.GetDst(0) != None: 
                        #Workaround for why it's printing in nodes that aren't connected
                        if not lAnimationNode.GetDst(i).GetOwner().Name.startswith("Relation"):
                            lOut = 1
            #IN  Animation Nodes
            lAnimationNodesIN = lBox.AnimationNodeInGet().Nodes
            for lAnimationNode in lAnimationNodesIN:
                for i in range(lAnimationNode.GetSrcCount()):
                    if lAnimationNode.GetSrc(0) != None:
                        lIn = 1
            if lOut == 0 and lIn == 1:
                print "%s is a Receiver Box" % lBox.Name
            elif lOut == 1 and lIn == 0:
                print "%s is a Sender Box" % lBox.Name
            else:
                print "%s is a Function (operator) Box" % lBox.Name  
        print
        print "**********************************************************************"
        print "***These are the connections between the boxes in the %s Constraint***" % lCon.Name
        print "**********************************************************************"
        for lBox in lCon.Boxes:
            print "-------%s Box connected Animation Nodes-------" % lBox.Name
            #OUT Animation Nodes
            #looks like we have an issue with Out Animation Nodes, I think it prints in nodes too :(
            lAnimationNodesOUT = lBox.AnimationNodeOutGet().Nodes
    
            for lAnimationNode in lAnimationNodesOUT:
                for i in range(lAnimationNode.GetDstCount()):
                    if lAnimationNode.GetDst(0) != None: 
                        #Workaround for why it's printing in nodes that aren't connected
                        if not lAnimationNode.GetDst(i).GetOwner().Name.startswith("Relation"):
                            print "OUT: %s (%s) > %s (%s) " % (lBox.Name, lAnimationNode.UserName, lAnimationNode.GetDst(i).GetOwner().Name, lAnimationNode.GetDst(i).UserName)
            
            #IN  Animation Nodes
            lAnimationNodesIN = lBox.AnimationNodeInGet().Nodes
            for lAnimationNode in lAnimationNodesIN:
                for i in range(lAnimationNode.GetSrcCount()):
                    if lAnimationNode.GetSrc(0) != None:
                        print "IN: %s (%s) > %s (%s) " % (lBox.Name, lAnimationNode.UserName, lAnimationNode.GetSrc(0).GetOwner().Name, lAnimationNode.GetSrc(0).UserName)                    
            print