Python API 2.0 Reference
python/api1/py1BasicObjectSet.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 # Creation Date: 12 October 2006
40 
41 ########################################################################
42 # DESCRIPTION:
43 #
44 # Produces an objectSet node "spBasicObjectSet".
45 #
46 # This plug-in implements a proxy objectSet node and a command for adding
47 # selected elements to a newly created spBasicObjectSet.
48 #
49 # To create one of these nodes, enter the following commands after the plug-in
50 # is loaded:
51 #
52 # import maya.cmds as cmds
53 # cmds.createNode("spBasicObjectSet")
54 #
55 # An example script basicObjectSetTest.py is supplied in the developer kit.
56 # This example adds and removes objects from a spBasicObjectSet node.
57 #
58 ########################################################################
59 
60 import maya.OpenMaya as OpenMaya
61 import maya.OpenMayaMPx as OpenMayaMPx
62 import math, sys
63 
64 kNodeName = "spBasicObjectSet"
65 kCmdName = "spBasicObjectSetTest"
66 kNodeId = OpenMaya.MTypeId(0x00080065)
67 
68 # Node definition
69 class BasicObjectSet(OpenMayaMPx.MPxObjectSet):
70  def __init__(self):
71  OpenMayaMPx.MPxObjectSet.__init__(self)
72 
73 
74 class BasicObjectSetTest(OpenMayaMPx.MPxCommand):
75  def __init__(self):
76  OpenMayaMPx.MPxCommand.__init__(self)
77  self.__fDGMod = OpenMaya.MDGModifier()
78 
79 
80  def doIt(self, args):
81  # Create the node
82  #
83  setNode = self.__fDGMod.createNode(kNodeId)
84  self.__fDGMod.doIt()
85 
86  # Populate the set with the selected items
87  #
88  selList = OpenMaya.MSelectionList()
90  if selList.length():
91  setFn = OpenMaya.MFnSet(setNode)
92  setFn.addMembers(selList)
93 
94  depNodeFn = OpenMaya.MFnDependencyNode(setNode)
95  OpenMayaMPx.MPxCommand.setResult(depNodeFn.name())
96 
97 
98 #####################################################################
99 
100 
101 # creator
102 def nodeCreator():
103  return OpenMayaMPx.asMPxPtr(BasicObjectSet())
104 
105 
106 # initializer
107 def nodeInitializer():
108  # nothing to initialize
109  pass
110 
111 
112 def cmdCreator():
113  return OpenMayaMPx.asMPxPtr(BasicObjectSetTest())
114 
115 
116 def cmdSyntaxCreator():
117  return OpenMaya.MSyntax()
118 
119 
120 # initialize the script plug-in
121 def initializePlugin(mobject):
122  mplugin = OpenMayaMPx.MFnPlugin(mobject, "Autodesk", "1.0", "Any")
123  try:
124  mplugin.registerCommand(kCmdName, cmdCreator, cmdSyntaxCreator)
125  except:
126  sys.stderr.write("Failed to register command: %s" % kCmdName)
127  raise
128 
129  try:
130  mplugin.registerNode(kNodeName, kNodeId, nodeCreator, nodeInitializer, OpenMayaMPx.MPxNode.kObjectSet)
131  except:
132  sys.stderr.write("Failed to register node: %s" % kNodeName)
133  raise
134 
135 
136 # uninitialize the script plug-in
137 def uninitializePlugin(mobject):
138  mplugin = OpenMayaMPx.MFnPlugin(mobject)
139  try:
140  mplugin.deregisterCommand(kCmdName)
141  except:
142  sys.stderr.write("Failed to deregister command: %s" % kCmdName)
143  raise
144 
145  try:
146  mplugin.deregisterNode(kNodeId)
147  except:
148  sys.stderr.write("Failed to deregister node: %s" % kNodeName)
149  raise