61 import maya.OpenMaya
as OpenMaya
62 import maya.OpenMayaUI
as OpenMayaUI
63 import maya.OpenMayaMPx
as OpenMayaMPx
66 contextCmdName =
"spMoveManipCtxCmd"
67 nodeName =
"spMoveManip"
69 class moveManip(OpenMayaMPx.MPxManipContainer):
74 OpenMayaMPx.MPxManipContainer.__init__(self)
76 def createChildren(self):
77 self.fDistanceManip = self.addDistanceManip(
"distanceManip",
"distance")
81 distanceManipFn.setStartPoint(startPoint)
82 distanceManipFn.setDirection(direction)
83 self.fFreePointManip = self.addFreePointTriadManip(
"pointManip",
"freePoint")
85 def connectToDependNode(self, node):
89 syPlug = nodeFn.findPlug(
"scaleY")
90 tPlug = nodeFn.findPlug(
"translate")
92 distanceManipFn.connectToDistancePlug(syPlug)
94 freePointManipFn.connectToPointPlug(tPlug)
95 OpenMayaMPx.MPxManipContainer.finishAddingManips(self)
96 OpenMayaMPx.MPxManipContainer.connectToDependNode(self,node)
98 sys.stderr.write(
"Error finding and connecting plugs\n" )
101 def moveManipCreator():
102 return OpenMayaMPx.asMPxPtr( moveManip() )
104 def moveManipInitialize():
105 OpenMayaMPx.MPxManipContainer.initialize()
107 class moveManipContext(OpenMayaMPx.MPxSelectionContext):
109 OpenMayaMPx.MPxSelectionContext.__init__(self)
111 def toolOnSetup(self,event):
112 updateManipulators(self)
115 def updateManipulators(clientData):
116 clientData.deleteManipulators()
121 while not selectionIter.isDone():
123 selectionIter.getDependNode(dependNode)
124 if dependNode.isNull()
or not dependNode.hasFn(OpenMaya.MFn.kDependencyNode):
125 print "depend node is null"
129 rPlug = dependNodeFn.findPlug(
"translate",
False)
130 sPlug = dependNodeFn.findPlug(
"scaleY",
False)
131 if rPlug.isNull()
or sPlug.isNull():
132 print "translate and/or scale plugs are null"
137 manipulator = OpenMayaMPx.MPxManipContainer.newManipulator(nodeName, manipObject)
138 if manipulator
is not None:
139 clientData.addManipulator(manipObject)
140 manipulator.connectToDependNode(dependNode)
143 class moveManipCtxCmd(OpenMayaMPx.MPxContextCommand):
145 OpenMayaMPx.MPxContextCommand.__init__(self)
148 return OpenMayaMPx.asMPxPtr( moveManipContext() )
151 def contextCmdCreator():
152 return OpenMayaMPx.asMPxPtr( moveManipCtxCmd() )
156 def initializePlugin(mobject):
157 mplugin = OpenMayaMPx.MFnPlugin(mobject)
160 mplugin.registerContextCommand( contextCmdName, contextCmdCreator )
162 print "Failed to register context command: %s" % contextCmdName
166 mplugin.registerNode(nodeName, moveManipId, moveManipCreator, moveManipInitialize, OpenMayaMPx.MPxNode.kManipContainer)
168 print "Failed to register node: %s" % nodeName
172 def uninitializePlugin(mobject):
173 mplugin = OpenMayaMPx.MFnPlugin(mobject)
175 mplugin.deregisterContextCommand(contextCmdName)
177 print "Failed to deregister context command: %s" % contextCmdName
181 mplugin.deregisterNode(moveManipId)
183 print "Failed to deregister node: %s" % nodeName