Python API 2.0 Reference
python/api1/py1CircleNodeTest.py
1 #-
2 # ==========================================================================
3 # Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All
4 # rights reserved.
5 #
6 # The coded instructions, statements, computer programs, and/or related
7 # material (collectively the "Data") in these files contain unpublished
8 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
9 # licensors, which is protected by U.S. and Canadian federal copyright
10 # law and by international treaties.
11 #
12 # The Data is provided for use exclusively by You. You have the right
13 # to use, modify, and incorporate this Data into other products for
14 # purposes authorized by the Autodesk software license agreement,
15 # without fee.
16 #
17 # The copyright notices in the Software and this entire statement,
18 # including the above license grant, this restriction and the
19 # following disclaimer, must be included in all copies of the
20 # Software, in whole or in part, and all derivative works of
21 # the Software, unless such copies or derivative works are solely
22 # in the form of machine-executable object code generated by a
23 # source language processor.
24 #
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
26 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
27 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
28 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
29 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
30 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
31 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
32 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
33 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
34 # OR PROBABILITY OF SUCH DAMAGES.
35 #
36 # ==========================================================================
37 #+
38 
39 #
40 # Autodesk Script File
41 # MODIFY THIS AT YOUR OWN RISK
42 #
43 # Creation Date: 27 September 2006
44 #
45 # Description:
46 # This script creates a new top level Maya menu that contains a
47 # single item "Move in Circle". When selected, it will create
48 # a sphere and a dependency node that moves this in a circle,
49 # and connect these 2 together.
50 #
51 # When the play button on the time slider is pressed, the sphere
52 # will move in a cirle around the Y axis.
53 #
54 # Procedures:
55 # circleMenu, createSphereAndAttachCircleNode
56 #
57 
58 import maya.cmds as cmds
59 
60 # Callback routine for the menu item created in CircleMenu
61 def createSphereAndAttachCircleNode(*args):
62  # Create a circle node dependency object called "circleNode1"
63  cmds.createNode("spCircle", name="circleNode1")
64 
65  # Create a sphere called "sphere1"
66  cmds.sphere(name="sphere1", radius=1)
67 
68  # Connect the sine output attribute of "circleNode1"
69  # to the X position of "sphere1"
70  cmds.connectAttr("circleNode1.sineOutput", "sphere1.translateX")
71 
72  # Connect the cosine output attribute of "circleNode1"
73  # to the Z position of "sphere1"
74  cmds.connectAttr("circleNode1.cosineOutput", "sphere1.translateZ")
75 
76  # Connect the output of the time slider, "time1", in frames
77  # to the input of "circleNode1".
78  cmds.connectAttr("time1.outTime", "circleNode1.input")
79 
80  # "circleNode1" will now compute the X and Z positions of "sphere1"
81  # as a function of the frame in the current animation.
82 
83 def circleMenu():
84  # The global string variable gMainWindow contains the name of top
85  # Level Maya window. Using this as the parent in a menu command
86  # will create a new menu at the same level as "File", "Edit", etc.
87  mainWindow = maya.mel.eval( "global string $gMainWindow;$temp = $gMainWindow" )
88 
89  # Create a top level menu called "Circle". Its only menu item
90  # is called "Move in circle", and when invoked by the user, it
91  # will call the createSphereAndAttachCircleNode procedure shown above.
92  cmds.menu("circleMenu", parent=mainWindow, tearOff=True, label="Circle")
93  cmds.menuItem("circleMenuItem1", label="Move in circle", command=createSphereAndAttachCircleNode)
94 
95 # Run circleMenu to add "Circle" to the top level Maya menu list.
96 circleMenu()