Python API 2.0 Reference
cameraMessageCmd/cameraMessageTest2.py
1 """
2 This is example code demonstrating how to add and remove MCameraMessages using the
3 Maya Python API 2.0 .
4 
5 """
6 
7 import maya.api.OpenMaya as OpenMaya
8 import maya.cmds
9 
10 def beginManipCB(node, clientData):
11  print("Inside beginManipCB, clientData is %s"%clientData)
12 def endManipCB(node, clientData):
13  print("Inside endManipCB, clientData is %s"%clientData)
14 
15 callbackIDs = []
16 
17 def test():
18  addCallbacksToPerspCamera()
19 
20 def addCallbacksToPerspCamera():
21  global callbackIDs
22  camFn = OpenMaya.MFnCamera()
23 
24  # For simplicity, select the persp camera's shape
25  #
26  maya.cmds.select('perspShape')
27 
28  # Create a selection list iterator
29  #
31  iter = OpenMaya.MItSelectionList(slist)
32 
33  print("List length is %d"%slist.length())
34 
35  # Iterate over all selected dependency nodes
36  #
37  while not iter.isDone():
38  # Get the selected dependency node
39  #
40  dependNode = iter.getDependNode()
41  dagPath = iter.getDagPath()
42  print("Node: %s"%dagPath.partialPathName())
43  if (dependNode.hasFn(OpenMaya.MFn.kCamera)):
44  print("This is a camera, adding manipulation callbacks with payloads")
45  payloadBegin = "12345.5"
46  payloadEnd = "54321.5"
47 
48  # Add the begin manipulation and end manipulation callbacks to the camera shape
49  #
50  callbackIDs.append(
51  OpenMaya.MCameraMessage.addBeginManipulationCallback(dependNode, beginManipCB, payloadBegin)
52  )
53  callbackIDs.append(
54  OpenMaya.MCameraMessage.addEndManipulationCallback(dependNode, endManipCB, payloadEnd)
55  )
56  else:
57  print("This node is not a camera...")
58 
59  next(iter)
60 
61 def removeCallbacks():
62  global callbackIDs
63  for id in callbackIDs:
65  callbackIDs = []
66 
67 """
68 import cameraMessageTest2 as cmt2
69 
70 maya.cmds.file(f=1,new=1)
71 reload(cmt2)
72 
73 cmt2.test()
74 cmt2.removeCallbacks()
75 """