Python API 2.0 Reference
python/api2/py2PanelCanvasInfo.py
1 import maya.api.OpenMaya as om
2 import maya.api.OpenMayaAnim as oma
3 import maya.api.OpenMayaUI as omu
4 import maya.api.OpenMayaRender as omr
5 import maya.mel as mel
6 import maya.cmds as cmds
7 
8 ##############################################################################
9 # #
10 # Primitive drawings with MUIDrawManager using callbacks #
11 # #
12 ##############################################################################
13 
14 def createScene():
15 
16  # Create an animated cylinder, and set a time range of [0,30]
17  #
18  cmds.file(force=1,new=1)
19  myCyl = cmds.polyCylinder()
20  cmds.setAttr( "pCylinder1.s",1, 3.3522764559816802, 1, type="double3" )
21 
22  cmds.playbackOptions(min=0, ast=0, max=30, aet=30)
23  cmds.currentTime( 0 )
24  cmds.setAttr( 'pCylinder1.tz', 12 )
25  cmds.setAttr( 'pCylinder1.rx', 30 )
26  cmds.setKeyframe( ['pCylinder1.tz','pCylinder1.rx'])
27 
28  cmds.currentTime(15)
29  cmds.setAttr( 'pCylinder1.tz', 0 )
30  cmds.setAttr( 'pCylinder1.rx', 0 )
31  cmds.setKeyframe( ['pCylinder1.tz','pCylinder1.rx'])
32 
33  cmds.currentTime(30)
34  cmds.setAttr( 'pCylinder1.tz', -12 )
35  cmds.setAttr( 'pCylinder1.rx', -30 )
36  cmds.setKeyframe( ['pCylinder1.tz','pCylinder1.rx'])
37 
38 def createGraphEditor():
39  # Create a Graph Editor for testing purposes
40  #
41  geName = 'myGraphEditorGraphEd';
42  if( cmds.scriptedPanel('myGraphEditor', exists=1) ):
43  cmds.deleteUI('myGraphEditor')
44 
45  geWindow = cmds.window(width=1200,height=800)
46  gePane = cmds.paneLayout(parent=geWindow)
47  cmds.scriptedPanel('myGraphEditor',type='graphEditor', parent=gePane,tearOff=False)
48  cmds.setParent('..')
49  cmds.showWindow(geWindow)
50  return [geName, geWindow]
51 
52 def maya_useNewAPI():
53  pass
54 
55 def initializePlugin( mobject ):
56  """
57  Description:
58  this method is called when the plug-in is loaded into Maya. It
59  registers all of the services that this plug-in provides with
60  Maya.
61 
62  Arguments:
63  mobject - a handle to the plug-in object (use MFnPlugin to access it)
64  """
65  createScene()
66  [geName, geWindow] = createGraphEditor()
67  geCanvasInfo = omu.MPanelCanvasInfo(geName)
68  global myCanvasInfo
69  myCanvasInfo = [geCanvasInfo, geName, geWindow]
70 
71  # Get the viewport size, and print it
72  #
73  viewportSize = geCanvasInfo.getViewportSize()
74  print('viewportSize')
75  print(viewportSize)
76 
77  # Get the bounds, and print them
78  #
79  viewportBounds = geCanvasInfo.getViewportBounds()
80  print('viewportBounds')
81  print(viewportBounds)
82 
83  # Shrink the bounds by 10%, set, get and print new values
84  #
85  viewportBounds[0] = viewportBounds[0]*0.9
86  viewportBounds[1] = viewportBounds[1]*0.9
87  viewportBounds[2] = viewportBounds[2]*0.9
88  viewportBounds[3] = viewportBounds[3]*0.9
89 
90  geCanvasInfo.setViewportBounds( viewportBounds )
91  newViewportBounds = geCanvasInfo.getViewportBounds()
92 
93  if( geCanvasInfo.supportsUIDrawing() ):
94  print('Editor supports UI Drawing')
95 
96  defaultCanvasInfo = omu.MPanelCanvasInfo('graphEditor1GraphEd')
97 
98  if( defaultCanvasInfo.supportsUIDrawing() ):
99  print('Default Graph Editor is ready for drawing')
100  else:
101  print('Default Graph Editor is not opened')
102 
103  print('newViewportBounds')
104  print(newViewportBounds)
105 
106 
107 def uninitializePlugin( mobject ):
108  """
109  Description:
110  this method is called when the plug-in is unloaded from Maya. It
111  deregisters all of the services that it was providing.
112 
113  Arguments:
114  mobject - a handle to the plug-in object (use MFnPlugin to access it)
115  """
116  global myCanvasInfo
117  [geCanvas, geName, geWindow] = myCanvasInfo
118  if cmds.window(geWindow, exists=True):
119  cmds.deleteUI(geWindow)
120