scripted/basicObjectSet.py

scripted/basicObjectSet.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 # Trivial extension of MPxObjectSet
44 #
45 
46 import maya.OpenMaya as OpenMaya
47 import maya.OpenMayaMPx as OpenMayaMPx
48 import math, sys
49 
50 kNodeName = "spBasicObjectSet"
51 kCmdName = "spBasicObjectSetTest"
52 kNodeId = OpenMaya.MTypeId(0x87012)
53 
54 # Node definition
55 class BasicObjectSet(OpenMayaMPx.MPxObjectSet):
56  def __init__(self):
57  OpenMayaMPx.MPxObjectSet.__init__(self)
58 
59 
60 class BasicObjectSetTest(OpenMayaMPx.MPxCommand):
61  def __init__(self):
62  OpenMayaMPx.MPxCommand.__init__(self)
63  self.__fDGMod = OpenMaya.MDGModifier()
64 
65 
66  def doIt(self, args):
67  # Create the node
68  #
69  setNode = self.__fDGMod.createNode(kNodeId)
70  self.__fDGMod.doIt()
71 
72  # Populate the set with the selected items
73  #
74  selList = OpenMaya.MSelectionList()
75  OpenMaya.MGlobal.getActiveSelectionList(selList)
76  if selList.length():
77  setFn = OpenMaya.MFnSet(setNode)
78  setFn.addMembers(selList)
79 
80  depNodeFn = OpenMaya.MFnDependencyNode(setNode)
81  OpenMayaMPx.MPxCommand.setResult(depNodeFn.name())
82 
83 
84 #####################################################################
85 
86 
87 # creator
88 def nodeCreator():
89  return OpenMayaMPx.asMPxPtr(BasicObjectSet())
90 
91 
92 # initializer
93 def nodeInitializer():
94  # nothing to initialize
95  pass
96 
97 
98 def cmdCreator():
99  return OpenMayaMPx.asMPxPtr(BasicObjectSetTest())
100 
101 
102 def cmdSyntaxCreator():
103  return OpenMaya.MSyntax()
104 
105 
106 # initialize the script plug-in
107 def initializePlugin(mobject):
108  mplugin = OpenMayaMPx.MFnPlugin(mobject, "Autodesk", "1.0", "Any")
109  try:
110  mplugin.registerCommand(kCmdName, cmdCreator, cmdSyntaxCreator)
111  except:
112  sys.stderr.write("Failed to register command: %s" % kCmdName)
113  raise
114 
115  try:
116  mplugin.registerNode(kNodeName, kNodeId, nodeCreator, nodeInitializer, OpenMayaMPx.MPxNode.kObjectSet)
117  except:
118  sys.stderr.write("Failed to register node: %s" % kNodeName)
119  raise
120 
121 
122 # uninitialize the script plug-in
123 def uninitializePlugin(mobject):
124  mplugin = OpenMayaMPx.MFnPlugin(mobject)
125  try:
126  mplugin.deregisterCommand(kCmdName)
127  except:
128  sys.stderr.write("Failed to deregister command: %s" % kCmdName)
129  raise
130 
131  try:
132  mplugin.deregisterNode(kNodeId)
133  except:
134  sys.stderr.write("Failed to deregister node: %s" % kNodeName)
135  raise