scripted/zoomCameraCmd.py

scripted/zoomCameraCmd.py
1 
2 #-
3 # ==========================================================================
4 # Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All
5 # rights reserved.
6 #
7 # The coded instructions, statements, computer programs, and/or related
8 # material (collectively the "Data") in these files contain unpublished
9 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
10 # licensors, which is protected by U.S. and Canadian federal copyright
11 # law and by international treaties.
12 #
13 # The Data is provided for use exclusively by You. You have the right
14 # to use, modify, and incorporate this Data into other products for
15 # purposes authorized by the Autodesk software license agreement,
16 # without fee.
17 #
18 # The copyright notices in the Software and this entire statement,
19 # including the above license grant, this restriction and the
20 # following disclaimer, must be included in all copies of the
21 # Software, in whole or in part, and all derivative works of
22 # the Software, unless such copies or derivative works are solely
23 # in the form of machine-executable object code generated by a
24 # source language processor.
25 #
26 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
27 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
28 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
29 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
30 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
31 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
32 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
33 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
34 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
35 # OR PROBABILITY OF SUCH DAMAGES.
36 #
37 # ==========================================================================
38 #+
39 
40 
41 # import maya.cmds
42 # maya.cmds.loadPlugin("zoomCameraCmd.py")
43 # maya.cmds.spZoomCamera()
44 
45 import sys
46 import maya.OpenMaya as OpenMaya
47 import maya.OpenMayaUI as OpenMayaUI
48 import maya.OpenMayaMPx as OpenMayaMPx
49 
50 kPluginCmdName = "spZoomCamera"
51 
52 print "zoomCameraCmd.py has been imported...."
53 
54 # command
55 class scriptedCommand(OpenMayaMPx.MPxCommand):
56  camera = OpenMaya.MDagPath()
57  def __init__(self):
58  OpenMayaMPx.MPxCommand.__init__(self)
59 
60  def redoIt(self):
61  global camera
62  fnCamera = OpenMaya.MFnCamera(camera)
63  f1 = fnCamera.focalLength()
64  fnCamera.setFocalLength(f1 * 2.0)
65 
66  def undoIt(self):
67  global camera
68  fnCamera = OpenMaya.MFnCamera(camera)
69  f1 = fnCamera.focalLength()
70  fnCamera.setFocalLength(f1 / 2.0)
71 
72  def doIt(self, args):
73  global camera
74  camera = OpenMaya.MDagPath()
75  try:
76  OpenMayaUI.M3dView.active3dView().getCamera(camera)
77  except:
78  sys.stderr.write( "ERROR: getting camera \n" )
79  else:
80  self.redoIt()
81 
82  def isUndoable(self):
83  return True
84 
85 #Cmd Creator
86 def cmdCreator():
87  return OpenMayaMPx.asMPxPtr( scriptedCommand() )
88 
89 # Initialize the script plug-in
90 def initializePlugin(obj):
91  plugin = OpenMayaMPx.MFnPlugin(obj)
92  try:
93  plugin.registerCommand( kPluginCmdName, cmdCreator)
94  except:
95  sys.stderr.write( "Failed to register command: %s\n" % kPluginCmdName )
96 
97 # Uninitialize the script plug-in
98 def uninitializePlugin(obj):
99  plugin = OpenMayaMPx.MFnPlugin(obj)
100  try:
101  plugin.deregisterCommand(kPluginCmdName)
102  except:
103  sys.stderr.write( "Failed to unregister command: %s\n" % kPluginCmdName )
104 
105