Python API 2.0 Reference
python/api1/py1BasicObjectSetTest.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 # Creation Date: 12 October 2006
41 #
42 # Description:
43 # Tests out MPxObjectSet from python by creating a BasicMPxObjectSet
44 # and adding and removing objects from it
45 #
46 
47 import maya.mel
48 import maya.cmds as cmds
49 
50 # Main entry point
51 #
52 def testBasicObjectSet():
53  failures = testBasicObjectSetMain()
54  if failures > 0:
55  print("basicObjectSetTest: %d FAILED tests\n" % failures)
56  return failures
57 
58 
59 def testBasicObjectSetMain():
60  failures = 0
61 
62  # Test #1
63  #
64  # - Create a sphere and a cube.
65  # - Create a custom MPxObjectSet and add the sphere and cube to the set.
66  # - Delete the sphere.
67  # - Ensure the set is still present.
68  # - Delete the cube.
69  # - Ensure the set is deleted.
70  #
71  cmds.file(f=True, new=True)
72  sphere = cmds.polySphere(r=1, sx=20, sy=20, ax=(0, 1, 0), tx=1, ch=1)
73  cube = cmds.polyCube(w=1, h=1, d=1, sx=1, sy=1, sz=1, ax=(0, 1, 0), tx=1, ch=1)
74  cmds.select(sphere[0], cube[0])
75  objSet = maya.mel.eval("spBasicObjectSetTest")
76 
77  cmds.delete(sphere[0])
78  if not cmds.objExists(objSet):
79  failures += 1
80 
81  cmds.delete(cube[0])
82  if cmds.objExists(objSet):
83  failures += 1
84 
85  if failures > 0:
86  print("testBasicObjectSetMain (Test #1): FAILED\n")
87  failures = 0
88 
89  # Test #2
90  #
91  # - Create a sphere and a cube.
92  # - Create a custom MPxObjectSet and add the sphere to the set.
93  # - Connect the cube.message -> set.usedBy.
94  # - Delete the sphere.
95  # - Ensure the set is still present.
96  #
97  cmds.file(f=True, new=True)
98  sphere = cmds.polySphere(r=1, sx=20, sy=20, ax=(0, 1, 0), tx=1, ch=1)
99  cube = cmds.polyCube(w=1, h=1, d=1, sx=1, sy=1, sz=1, ax=(0, 1, 0), tx=1, ch=1)
100  cmds.select(sphere[0])
101  objSet = maya.mel.eval("spBasicObjectSetTest")
102  cmds.connectAttr("%s.message" % cube[0], "%s.usedBy[0]" % objSet)
103  cmds.delete(sphere[0])
104  if not cmds.objExists(objSet):
105  failures += 1
106 
107  if failures > 0:
108  print("testBasicObjectSetMain (Test #1): FAILED\n")
109 
110  # Clamp failures to 1.
111  #
112  if failures > 1:
113  failures = 1
114 
115  return failures