demoMakeInstances.py

demoMakeInstances.py
1 '''
2  Demonstrates creating instances of a node hierarchy.
3 '''
4 import MaxPlus
5 
6 
7 def createNodes(o, cnt):
8  return [MaxPlus.Factory.CreateNode(o) for i in xrange(cnt)]
9 
10 
11 def linkNodes(nodes):
12  for i in xrange(len(nodes) - 1):
13  nodes[i + 1].Parent = nodes[i]
14 
15 
16 def alignNodesInLine(nodes, pt):
17  for i in xrange(len(nodes)):
18  nodes[i].Move(MaxPlus.Point3(pt.X * i, pt.Y * i, pt.Z * i))
19 
20 
21 def main():
22  obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere)
23  obj.ParameterBlock.Radius.Value = 3.0
24  nodes = createNodes(obj, 10)
25  alignNodesInLine(nodes, MaxPlus.Point3(5, 0, 0))
26  linkNodes(nodes)
27  copy = nodes[0].CreateTreeInstance()
28  copy.Move(MaxPlus.Point3(0, 25, 0))
29 
30 if __name__ == "__main__":
31  main()