Tasks/TraversingRelationConstraint.py

Tasks/TraversingRelationConstraint.py
1 # Copyright 2010 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # This sample shows you how to traverse animation node connections in a relation constraint.
8 #
9 # Sample scene file this script works with: traversingRelationConstraint.fbx
10 #
11 # Topic: FBConstraintRelation, FBAnimationNode
12 
13 from pyfbsdk import *
14 
15 lCons = FBSystem().Scene.Constraints
16 #Going through the constraints in the scene
17 print "********************************************"
18 print "***These are the constraints in the scene***"
19 print "********************************************"
20 for lCon in lCons:
21  print "Constraint Name ->", lCon.Name
22 
23 print
24 for lCon in lCons:
25  if lCon.Is( FBConstraintRelation_TypeInfo() ):
26  print "*************************************************"
27  print "***These are the %d boxes in the %s Constraint***" % (len(lCon.Boxes), lCon.Name)
28  print "*************************************************"
29  for lBox in lCon.Boxes:
30  lOut = 0
31  lIn = 0
32  lAnimationNodesOUT = lBox.AnimationNodeOutGet().Nodes
33  for lAnimationNode in lAnimationNodesOUT:
34  for i in range(lAnimationNode.GetDstCount()):
35  if lAnimationNode.GetDst(0) != None:
36  #Workaround for why it's printing in nodes that aren't connected
37  if not lAnimationNode.GetDst(i).GetOwner().Name.startswith("Relation"):
38  lOut = 1
39  #IN Animation Nodes
40  lAnimationNodesIN = lBox.AnimationNodeInGet().Nodes
41  for lAnimationNode in lAnimationNodesIN:
42  for i in range(lAnimationNode.GetSrcCount()):
43  if lAnimationNode.GetSrc(0) != None:
44  lIn = 1
45  if lOut == 0 and lIn == 1:
46  print "%s is a Receiver Box" % lBox.Name
47  elif lOut == 1 and lIn == 0:
48  print "%s is a Sender Box" % lBox.Name
49  else:
50  print "%s is a Function (operator) Box" % lBox.Name
51  print
52  print "**********************************************************************"
53  print "***These are the connections between the boxes in the %s Constraint***" % lCon.Name
54  print "**********************************************************************"
55  for lBox in lCon.Boxes:
56  print "-------%s Box connected Animation Nodes-------" % lBox.Name
57  #OUT Animation Nodes
58  #looks like we have an issue with Out Animation Nodes, I think it prints in nodes too :(
59  lAnimationNodesOUT = lBox.AnimationNodeOutGet().Nodes
60 
61  for lAnimationNode in lAnimationNodesOUT:
62  for i in range(lAnimationNode.GetDstCount()):
63  if lAnimationNode.GetDst(0) != None:
64  #Workaround for why it's printing in nodes that aren't connected
65  if not lAnimationNode.GetDst(i).GetOwner().Name.startswith("Relation"):
66  print "OUT: %s (%s) > %s (%s) " % (lBox.Name, lAnimationNode.UserName, lAnimationNode.GetDst(i).GetOwner().Name, lAnimationNode.GetDst(i).UserName)
67 
68  #IN Animation Nodes
69  lAnimationNodesIN = lBox.AnimationNodeInGet().Nodes
70  for lAnimationNode in lAnimationNodesIN:
71  for i in range(lAnimationNode.GetSrcCount()):
72  if lAnimationNode.GetSrc(0) != None:
73  print "IN: %s (%s) > %s (%s) " % (lBox.Name, lAnimationNode.UserName, lAnimationNode.GetSrc(0).GetOwner().Name, lAnimationNode.GetSrc(0).UserName)
74  print
75 
76 
77 
78